seq產(chǎn)生等差序列
有以下幾個參數(shù)
- from,to起始數(shù)字和結(jié)束數(shù)字
> seq(2,10) [1] 2 3 4 5 6 7 8 9 10
- seq(from, to, by= ) #by指定步長
> seq(2,10,by=3) [1] 2 5 8
- seq(from, to, length.out= ) #指定長度,length.out=length
> seq(0, 1, length= 11) [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
對一組向量則按下標(biāo)產(chǎn)生序列
x<-c(11,22,33,44,55,66,77)
> seq(x)#以長度(下標(biāo))生成序列
[1] 1 2 3 4 5 6 7```
###rep產(chǎn)生重復(fù)序列
參數(shù)
rep.int(x, times)# x要重復(fù)的對象 times重復(fù)的次數(shù)
`> rep(1:4, 2)
[1] 1 2 3 4 1 2 3 4`
rep_len(x, each=)# each單個循環(huán)重復(fù),如果不傳入each參數(shù)則連續(xù)循環(huán)
`> rep(1:4, each = 2) # not the same.
[1] 1 1 2 2 3 3 4 4`
`> rep(1:4, c(2,1,2,1))#可指定某個向量循環(huán)的次數(shù)
[1] 1 1 2 3 3 4`
length指定長度
`> rep(1:4, each = 2, len = 4) # first 4 only.
[1] 1 1 2 2
> rep(1:4, each = 2, len = 10) # 8 integers plus two recycled 1's.
[1] 1 1 2 2 3 3 4 4 1 1`