Prof Brian Ripley wrote:
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.
Hmm, you could well be right there. Not quite a simple spot change,
though. As far as I see, either it needs do.call, or maybe there is a
much more radical simplification possible. I'll have a look.
BTW, we have a deparser bug:
> transform
function ("_data", ...)
UseMethod("transform")
<environment: namespace:base>
> function ("_data", ...)
Error: unexpected string constant in "function ("_data""
....
> f <- function (`_data`, ...) {}
> attr(f,"source")<-NULL
> f
function ("_data", ...)
{
}
It should deparse with backticks, not the old-style quotes (did that
ever work?).
--
O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
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.