【发布时间】:2020-05-17 17:07:02
【问题描述】:
我有一个向量,我想用某种模式将它拆分成多个向量。例如:
a table x with a vector of 14 numbers like:
x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
我想根据上面的向量创建一个包含多个向量的新表
n=2,m1=3,m2=4
column n=2, for column1:row=n*m1 and column2: row= n*m2 (Here, the number could be variables)
1 7
2 8
3 9
4 10
5 11
6 12
13
14
非常感谢
【问题讨论】:
-
n <- 2; split(1:14, rep(1:2, n*3:4))也许吧。 -
如果表中你的意思是data.frame,这可能几乎是你想要的? stackoverflow.com/questions/46380954/…
-
n
-
嗨,snd,因为链接的解决方案看起来不是我想要的。我无法理解编码。有更简单的解决方案吗?
-
@Michale 如果您看到错误“数据长度不是拆分变量的倍数”,您应该提供模拟您的实际问题的示例数据。
标签: r