Skip to content
Back to formatted view

Raw Message

Message-ID: <op.ulk2y7qvw9ljuw@tir-070312.staff.few.eur.nl>
Date: 2008-12-03T11:17:21Z
From: Vitalie S.
Subject: Bug in "transform"?
In-Reply-To: <alpine.LFD.2.00.0812030845540.21836@gannet.stats.ox.ac.uk>

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.