[R] Inflate/Expand/Resize an array

Mark Payne mpa at difres.dk
Fri Apr 27 11:41:34 CEST 2007


Gudday,

I've had a good look everywhere trying to figure out how to do this, but
I'm afraid I can seem to find an answer anywhere - maybe its because I'm
not using the right terms, or maybe its because I'm a dummy. But
unfortunately, I am not completely and utterly stuck. Here's the
problem:

I have two large, six dimensional arrays that I would like to add
together. Lets call them f and m. Their dimensions are respectively:

> dim(f)
[1] 10  25  1  1  1 14
> dim(m)
[1] 10 1 1 1 1 14

You can see that they're pretty close in size, but not identical. What I
would like to do is expand or inflate m along its second dimension so
that it ends up with dimension 10 25 1 1 1 14, so that I can then add
the two together - the new values created along that second dimension
would simply be copies of the first value..

What's the fastest way to do this? Is there a dedicated function?
Ideally I envisage something that you feed the input array, and the
desired dimensions, and it does the rest for you. Please also bear in
mind that this is a specific problem - the more general case is where I
don't know which dimensions are "out of shape", so to speak...

I hope that's clear, and that someone can me out here...

Cheers,

Mark



More information about the R-help mailing list