[R] scaling-centering a vector using an index

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Sep 5 19:07:59 CEST 2002


Thomas de Cornulier <oedic at cebc.cnrs.fr> writes:

> split and unsplit do what I need, but I don't understand why the first call
> is the example below doesn't work as the second do:
> 
> x<-rnorm(10,3)
> f1<-rep(c("a","b"),5)
> f2<-rep(c("c","d"),c(5,5))
> unsplit(lapply(split(x,list(f1,f2)),scale),list(f1,f2)) ##first call

That was a dumb bug in unsplit that was fixed in the development
sources a while back:

> unsplit
function (value, f) 
{
    len <- length(if (is.list(f)) f[[1]] else f)
    x <- vector(mode = typeof(value[[1]]), length = len)
    split(x, f) <- value
    x
}

(the bug being that we used length(f) unconditionally in 1.5.1)


-- 
   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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list