[R] prevent conversion to factors in aggregate?

Dieter Menne dieter.menne at menne-biomed.de
Sun Nov 16 19:23:55 CET 2003


Spencer Graves wrote

>>I don't know how to prevent aggregate from making factors of everything,
>>but the following shows how to cast them back into what you want:
....
> DF.$bch <- as.character(DF.$b)
> DF.$dn <- as.numeric(as.character(DF.$d))
> sapply(DF., class)
...

----
help(factor) suggests:

"To “revert” a factor f to its original numeric values,
as.numeric(levels(f))[f] is recommended and slightly more efficient than
as.numeric(as.character(f)). "

And in package Hmisc there is a function "summarize" that does not touch
non-factors.

Dieter Menne




More information about the R-help mailing list