在 R 编程中生成传递参数的长度序列 – seq_along()函数
R 语言中的seq_along()
函数用于生成与传递的参数长度相同的序列。
Syntax: seq_along(x)
Parameters:
x: specified arguments
示例 1:
# R program to illustrate
# seq_along function
# Calling the seq_along() function
seq_along(letters[1:4])
seq_along(letters[0:3])
输出:
[1] 1 2 3 4
[1] 1 2 3
示例 2:
# R program to illustrate
# seq_along function
# Calling the seq_along() function
seq_along(c(1, 2, 3))
seq_along(c(5, 10, 15, 20))
seq_along(c(2, 4))
seq_along(10)
seq_along(2)
输出:
[1] 1 2 3
[1] 1 2 3 4
[1] 1 2
[1] 1
[1] 1