[R] Change array size

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Fri Feb 14 14:48:03 CET 2003


"Liaw, Andy" <andy_liaw at merck.com> writes:

> Is the following what you want?
> 
> > x<- rnorm(800)
> > xt <- x[1:2^trunc(log(length(x),base=2))]
> > length(xt)
> [1] 512

I don't think so (notice "upper"). More likely

x <- rnorm(800)
l <- length(x)
xt <- c(x,numeric(2^ceiling(log(l,base=2))-l))
length(xt) # 1024

but "fits" might also imply interpolation?

> > 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.


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list