Skip to content
Prev 68830 / 398506 Next

Subarrays

Tony Plate <tplate at acm.org> writes:
It's generally a pain anyways... One possible alternative is to use
TRUE instead
[,1] [,2] [,3] [,4]
[1,]   67   83   99  115
[2,]   71   87  103  119
[3,]   75   91  107  123
[4,]   79   95  111  127

The alist() function can be used to generate the missing argument in a
somewhat clean way. E.g.,

ix <- as.list(dim(v))
ix[c(1,4)] <- c(3,2)
ix[-c(1,4)] <- alist(a=) # name disappears
do.call("[",c(list(v),ix))

(BTW, it surprised me a little that you don't need as.list() on the
right hand side of ix[c(1,4)] <- c(3,2), anyone know the rationale?)