Generate a Sequence from 1 to any Specified Number in R Programming – seq_len() Function

seq_len() function in R Language is used to generate a sequence from 1 to the specified number.

Syntax: seq_len(x)

Parameters:
x: specified number

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# seq_len function
  
# Calling the seq_len() function
seq_len(1)
seq_len(3)
seq_len(0)
seq_len(6)

chevron_right


Output:

[1] 1
[1] 1 2 3
integer(0)
[1] 1 2 3 4 5 6

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# seq_len function
  
# Creating a vector of length 5
my_vector <- c(5, 6, 1, 13, 7)
  
# Calling seq_len() function
seq_len(length(my_vector))

chevron_right


Output:

[1] 1 2 3 4 5
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.