[R] summaryBy: transformed variable on RHS of formula?
Alexander Shenkin
ashenkin at ufl.edu
Mon Apr 2 17:58:43 CEST 2012
Hi Folks,
I'm trying to cut my data inside the summaryBy function. Perhaps
formulas don't work that way? I'd like to avoid adding another column
if possible, but if I have to, I have to. Any ideas?
Thanks,
Allie
require(doBy)
df = dataframe(a <- rnorm(100), b <-rnorm(100))
summaryBy(a ~ cut(b,c(-100,-1,1,100)), data=df) # preferred
solution, but it throws an error
# Error in
`[.data.frame`(data, , rh.var, drop = FALSE) : undefined columns selected
df$c = cut(b,c(-100,-1,1,100))
summaryBy(a ~ c, data=df) # works fine
More information about the R-help
mailing list