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 中重复另一个向量的元素 n 次来创建一个向量。
o <- (1, 2, 3) n = 3
我想看看 result_a (1,1,1,2,2,2,3,3,3) result_b (1,2,3,1,2,3,1,2,3)
谢谢,Z
rep下面是一个使用命令的简单示例:
rep
> o <- c(1,2,3) > n <- 3 > rep(o, each=3) [1] 1 1 1 2 2 2 3 3 3 > rep(o,3) [1] 1 2 3 1 2 3 1 2 3