[R] rbind to array members
RICHARD M. HEIBERGER
rmh at temple.edu
Mon Oct 19 21:27:28 CEST 2009
> z <- abind(x[,,1], c(4,5,6),along=0)
z is probably not what you want because you aren't using the drop=FALSE
argument. See the FAQ 7.5
abind, and arrays in general, are rectangular solids. They are not
ragged. For that you need lists. To get something like your request
> x
> , , 1
>
> [,1] [,2] [,3]
> [1,] 1 2 3
> [2,] 4 5 6
>
> , , 2
>
> [,1] [,2] [,3]
> [1,] 7 8 9
>
you need
> x <- list(matrix(1:6, 2, 3, byrow=TRUE),
+ matrix(7:9, 1, 3))
> x
[[1]]
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[[2]]
[,1] [,2] [,3]
[1,] 7 8 9
>
More information about the R-help
mailing list