On Tue, 2 Dec 2008, Peter Dalgaard wrote:

Prof Brian Ripley wrote:
As the help page says

     If some of the values are not vectors of the appropriate length,
     you deserve whatever you get!

Yes (did I write that?). It is a bit annoying with things that almost work, though.


[snip]

I often need to use this for creating new variables in data frame from those already present.
Sorely needed!!

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


...at least when you're not making use of the scoping aspects. And if you calculate at least one vector of full length, then the issue goes away.



transform(aq, a=1,b=2)
Error in data.frame(`_data`, e[!matched]) :
 arguments imply differing number of rows: 6, 1
transform(aq, a=1,b=2,o=Ozone)
   Ozone Solar.R Wind Temp Month Day a b  o
3      12     149 12.6   74     5   3 1 2 12
31     37     279  7.4   76     5  31 1 2 37
34     NA     242 16.1   67     6   3 1 2 NA
65     NA     101 10.9   84     7   4 1 2 NA
59     NA      98 11.5   80     6  28 1 2 NA
133    24     259  9.7   73     9  10 1 2 24



The underlying issue is actually not in transform() but in data.frame():

Well, no, it is in the way that you call data.frame(). If you want to add several variables, pass them as separate arguments rather than as a list (just as they were passed to transform.data.frame). That's a simple change and will make transform.data.frame behave more consistently with cbind.data.frame and data.frame.

--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to