MvG
MvG

Reputation: 60858

Multidimensional binding

For dealing with two-dimensional matrices, rbind and cbind are useful functions. Are there more generic functions to perform the same operation in more dimensions? Suppose I have data like this:

data <- lapply(c(11,22,33), function(i) matrix(i, nrow=2, ncol=4))

What I'd like to obtain is this:

data <- do.call(c, data)
dim(data) <- c(2, 4, 3)

but without having to work out all the dimensions myself.

Is there a function providing this functionality, either built-in or as part of a reasonably common package? Or do you want to share your own ideas of how such a function could be implemented most elegantly?

Bonus points:

Upvotes: 1

Views: 99

Answers (1)

joran
joran

Reputation: 173557

The abind package has precisely this function, with most of the features you mention, although I haven't checked all of them in detail.

At the very least, it would give you a start on how one would implement something along these lines.

Upvotes: 2

Related Questions