[R] prevent conversion to factors in aggregate?
Jeff D. Hamann
jeff.hamann at forestinformatics.com
Sun Nov 16 02:58:23 CET 2003
I've been trying to figure out how to prevent a column that is the result of
an aggregate function call so that I can use it in further calculations. For
example, I would like to aggregate the expf for the data.frame by sp
(character) and dbh (double d=rounded to integer) using the command:
> st2 <- aggregate( ntrs$expf, by=list(sp=ntrs$sp,dbh=ntrs$dbh), sum )
> st2$expf <- st2$x / 20
> st2$basal.area <- st2$dbh^2 * st2$expf
Warning message:
"^" not meaningful for factors in: Ops.factor(st2$dbh, 2)
>
attributes(st2$dbh) tell me the class is a factor. I would like to values to
remain AsIs but cannot seem to figure out how to tell aggregate how to do
that, or even handle the operation after the fact by converting or adding an
extra column to the resulting data.frame.
I've tried using I() with no luck
> st2 <- aggregate( ntrs$expf, by=list(sp=ntrs$sp,dbh=I(ntrs$dbh)), sum )
How can/do I "cast" the dbh factor into an integer in the data.frame?
Thanks,
Jeff.
---
Jeff D. Hamann
Forest Informatics, Inc.
PO Box 1421
Corvallis, Oregon USA 97339-1421
(office) 541-754-1428
(cell) 541-740-5988
jeff.hamann at forestinformatics.com
www.forestinformatics.com
More information about the R-help
mailing list