[R] Change array size

Jason Turner jasont at indigoindustrial.co.nz
Sun Feb 16 03:17:03 CET 2003


On Fri, Feb 14, 2003 at 09:51:38AM +0000, Poizot Emmanuel wrote:
> Hi,
> I would like to know if there is a way to change a vector of arbitrary size
> to make it fits the nearest upper size multiple of a power of 2.

Do you want to interpolate to a new shape, or zero-pad?  If
zero-padding is what you're after, I think nextn() is what you want...

> zz <- rnorm(10)
> zz.pad <- vector(length=nextn(length(zz),factors=2))
> zz.pad[1:length(zz)] <- zz
> zz.pad
 [1]  0.2759134 -1.3738876  0.9816857 -0.4639678 -1.0549718  2.8562435
 [7] -0.6275852  0.1169049  0.2463690  0.9059579  0.0000000  0.0000000
[13]  0.0000000  0.0000000  0.0000000  0.0000000

Cheers

Jason
-- 
Indigo Industrial Controls Ltd.
64-21-343-545
jasont at indigoindustrial.co.nz




More information about the R-help mailing list