rep()是一个重复value的函数。不需要package,是一个基本的本地功能。
rep.int()
rep_len()都是rep函数,是一种更快的简便版本。就不详细介绍
rep(x,times = , length.out = ,each = ,)#形式如此,x为重复的value,times是次数
> rep("1", times = 2)
[1] "1" "1"
> rep("1",times = 6,length.out = 2)#length.out是输出的长度,可以看到虽然重复了6次,但是输出了两次。
[1] "1" "1"
> rep("1",times = 6,length.out = 12)#但是短了也会补上
[1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
> rep("1",times = 6,each = 2)#each代表每次重复次数,可看到虽然重复6次。但是输出了12次结果
[1] "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1" "1"
一些其他的写法
> rep(c("normal","tumor"),each = 2)
[1] "normal" "normal" "tumor" "tumor"
> rep(c("normal","tumor"),times = 4)#注意如果没有each,则会出现如下情况,交替出现。很好理解
[1] "normal" "tumor" "normal" "tumor" "normal" "tumor" "normal" "tumor"
>