开发者

Does R have shorthand to generate a sequence of integers?

开发者 https://www.devze.com 2023-04-05 11:54 出处:网络
Does R have shorthand, function or operator开发者_开发百科 which I can use to easily generate the following vector?

Does R have shorthand, function or operator开发者_开发百科 which I can use to easily generate the following vector?

v1 <- c(1, 2, 3, 4, 5)

Something like

v1 <- 1..5


> 1:5
[1] 1 2 3 4 5

or

> seq(1, 5)
[1] 1 2 3 4 5

seq is quite flexible, in that it allows you to specify the stride, the desired number of output elements, etc., in various combinations:

## Default S3 method:
seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
    length.out = NULL, along.with = NULL, ...)

For example:

> seq(from=1, by=3, length.out=5)
[1]  1  4  7 10 13


Yes, you can use:

v1 <- 1:5
0

精彩评论

暂无评论...
验证码 换一张
取 消