简体   繁体   English

如何使用 R 中的模式将一个向量拆分为多个向量

[英]How to split one vector in to multiple vectors with pattern in R

I have a vector and I want to split it into multiple vectors with some pattern.我有一个向量,我想将它分成多个具有某种模式的向量。 For example:例如:

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

I want to create a new table with multiple vectors based on above vector我想根据上面的向量创建一个包含多个向量的新表

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

Many thanks非常感谢

markus's solution is correct.马库斯的解决方案是正确的。 Many thanks.非常感谢。

n <- 2; split(1:14, rep(1:2, n*3:4))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM