Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我执行:
a <- seq(1,1.5,0.1) b <- c(1,1.1,1.4,1.5) x <- rep(c(a,b),times=c(2,1))
rep(c(a, b), c(2, 1)) 中的错误:无效的“次”参数
为什么?
当我们连接 ( c) 两个向量时,它就变成了一个向量。如果想法是复制 'a' 2 和 'b' 1,我们将它们放在 alist中,然后使用rep。输出将是 a list,可以unlist编辑它以获得 a vector。
c
list
rep
unlist
vector
unlist(rep(list(a,b), c(2,1)))
标记的答案已经很完美了:这里有一个替代方法mapply
mapply
unlist(mapply(function(x,n)rep(x,n),list(a,b),c(2,1)))