[R] Bug in "transform"?

Vitalie Spinu vitosmail at rambler.ru
Wed Dec 3 12:17:21 CET 2008


Many thanks for your kind responses.


>  That's a simple change and will make transform.data.frame behave more  
> consistently with cbind.data.frame and data.frame.
>

Related to above, I find rather inconsistent following behavior:

> aq <- airquality[sample(1:153,6),]

> data.frame(aq, list(a=1,b=2))
Error in data.frame(aq, list(a = 1, b = 2)) :
   arguments imply differing number of rows: 6, 1

> cbind(aq,list(a1=1,a2=2))
Error in data.frame(..., check.names = FALSE) :
   arguments imply differing number of rows: 6, 1

but,

aq[c("a","b")]<-list(1,2) #works fine

In my understanding all versions above are conceptually similar and should  
behave in a same way, and recycling for one row data.frames should be a  
default. R is an interactive language and behavior like above is a real  
pain.

>>>  Just learn to use indexing: transform() is just syntactic sugar that  
>>> you are not making use of.
>>>

I really try to use indexing in code all the time I possibly can. But for  
interactive use with dozens of data transformations and reshapings per day  
- with just indexing I  would probably see stars at the end of the day.  
Thanks for existence of such "syntactic sugars" and for packages like   
Hadley's reshape and plyr.

Regards,
Vitalie.



More information about the R-help mailing list