在 R 编程中生成序列向量 – sequence()函数
R 语言中的sequence()
函数用于创建序列元素的向量。它创建具有指定长度和指定元素之间差异的向量。它类似于 seq()函数。
Syntax: sequence(x)
Parameters:
x: Maximum element of vector
示例 1:
# R program to create sequence of vectors
# Calling sequence() function
sequence(4)
sequence(6)
sequence(c(4, 6))
输出:
[1] 1 2 3 4
[1] 1 2 3 4 5 6
[1] 1 2 3 4 1 2 3 4 5 6
示例 2:
# R program to create sequence of vectors
# Calling sequence() function
sequence(1:4)
# Performing operations
x <- 2 * sequence(4)
x
输出:
[1] 1 1 2 1 2 3 1 2 3 4
[1] 2 4 6 8