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 的新用户。我在 R 中有两个向量,我想将这些向量放在一个矩阵中,如下所示:
x = c(1, 2, 3, 5, 4) y = c(1.1, 2.3, 4.5, 6.7, 5.5) > m [,1] [,2] [1,] 1 1.1 [2,] 2 2.3 [3,] 3 4.5 [4,] 5 5.5 [5,] 4 6.7
我怎么能在 R 中做到这一点?
您可以通过以下方式到达那里:
cbind(x,y[x]) x [1,] 1 1.1 [2,] 2 2.3 [3,] 3 4.5 [4,] 5 5.5 [5,] 4 6.7
如果 x 向量不是连续的,您仍然可以通过以下方式获得成功:
cbind(x, y[order(x)] )