Skip to content
Related Articles

Related Articles

Improve Article
Generate a Sequence from 1 to any Specified Number in R Programming – seq_len() Function
  • Last Updated : 24 Jun, 2020

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:




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

Output:

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

Example 2:




# 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))

Output:

[1] 1 2 3 4 5
My Personal Notes arrow_drop_up
Recommended Articles
Page :