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.
如何为 R 中“rep”函数中的“每个”参数分配多个值?一个简单的例子,向量中的每个值连续重复 3 次:
a <- seq(2,6,2) rep (a,each = 3)
但是,如果我在“每个”参数中添加多个值以更改每个值的重复次数,则它无法正常工作:
rep (a, each = c(2,4,7))
如何解决?先感谢您。
根据你认为的输出应该是什么,我猜你想要times=参数:
times=
rep (a, times = c(2, 4, 7)) # [1] 2 2 4 4 4 4 6 6 6 6 6 6 6
看看?rep有什么区别
?rep