簡體   English   中英

如何使用 R 中的模式將一個向量拆分為多個向量

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

我有一個向量,我想將它分成多個具有某種模式的向量。 例如:

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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM