Reputation: 349
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!
Upvotes: 0
Views: 79
Reputation: 132706
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
Upvotes: 1