[R] bug in unsplit()? (PR#1845)

p.dalgaard@biostat.ku.dk p.dalgaard@biostat.ku.dk
Sun, 28 Jul 2002 18:44:36 +0200 (MET DST)


Hedderik van Rijn <hedderik@cmu.edu> writes:

> > Thanks for pointing this out. I think your code should work, although
> > I'm slightly uneasy about actually modifying f, so how about
> 
> Just curious, why are you uneasy about that? Does it have side effects?

It is largely due superstition, but if you change f before calling
split<-() you have split() and split<-() called with different f's
even if the same f is used for split() and unsplit(). That can be
quite OK, but there's a marginal risk that it causes an inconsistency
somewhere so that the split and unsplit aren't exact inverses.

> >         len <- length(if (is.list(f)) f[[1]] else f)
> 
> The reason I used the interaction() call is that this seems to work too:
> 
>  > split(1:10,list(a=1:2,b=1:5))
> 
> So, lists with unequal lengths.

But does it work??

> unsplit(split(1:10,list(a=1:2,b=1:5)),interaction(list(a=1:2,b=1:5)))
[1] 1 6 2 7 3
Warning messages: 
1: longer object length
        is not a multiple of shorter object length in: ans * length(l) + as.integer(f) 
2: argument lengths differ in: split(x, f) 
3: longer object length
        is not a multiple of shorter object length in: ans * length(l) + as.integer(f) 
4: number of items to replace is not a multiple of replacement length 


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

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._