Skip to content
Related Articles

Related Articles

Improve Article

Generating sequenced Vectors in R Programming – sequence() Function

  • Last Updated : 15 Jun, 2020

sequence() function in R Language is used to create a vector of sequenced elements. It creates vectors with specified length, and specified differences between elements. It is similar to seq() function.

Syntax: sequence(x)

Parameters:
x: Maximum element of vector

Example 1:




# R program to create sequence of vectors
  
# Calling sequence() function
sequence(4)
sequence(6)
sequence(c(4, 6))

Output:

[1] 1 2 3 4
[1] 1 2 3 4 5 6
[1] 1 2 3 4 1 2 3 4 5 6

Example 2:




# R program to create sequence of vectors
  
# Calling sequence() function
sequence(1:4)
  
# Performing operations
x <- 2 * sequence(4)
x

Output:

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