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:
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:
sequence( 1 : 4 )
x < - 2 * sequence( 4 )
x
|
Output:
[1] 1 1 2 1 2 3 1 2 3 4
[1] 2 4 6 8
Share your thoughts in the comments
Please Login to comment...