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
精彩评论