Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 24 Jun, 2020
Like Article
Save Article
Similar Reads