简体   繁体   English

在R中的数组中重新排列行

[英]Rearranging rows in an array in R

I'm new to R and am certain this is likely a simple question but I can't seem to find the answer. 我是R的新手,可以肯定这可能是一个简单的问题,但我似乎找不到答案。 I have an array [36,21,12012]. 我有一个数组[36,21,12012]。 Is there a simple way to rearrange the array so that the bottom 24 rows are moved above the upper 12. 有没有一种简单的方法可以重新排列阵列,以便将底部的24行移到上方的12行之上。

Many thanks for any help! 非常感谢您的帮助!

myarray <- array(1:24, c(4,3,2))
#, , 1
#
#     [,1] [,2] [,3]
#[1,]    1    5    9
#[2,]    2    6   10
#[3,]    3    7   11
#[4,]    4    8   12
#
#, , 2
#
#     [,1] [,2] [,3]
#[1,]   13   17   21
#[2,]   14   18   22
#[3,]   15   19   23
#[4,]   16   20   24

myarray[c(3:4, 1:2),,]
#, , 1
#
#     [,1] [,2] [,3]
#[1,]    3    7   11
#[2,]    4    8   12
#[3,]    1    5    9
#[4,]    2    6   10
#
#, , 2
#
#     [,1] [,2] [,3]
#[1,]   15   19   23
#[2,]   16   20   24
#[3,]   13   17   21
#[4,]   14   18   22

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

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