简体   繁体   中英

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. I have an array [36,21,12012]. Is there a simple way to rearrange the array so that the bottom 24 rows are moved above the upper 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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