[R] Discretize factors?

Noah Silverman noah at smartmediacorp.com
Sat May 15 20:02:46 CEST 2010


Hi,

I'm looking for an easy way to discretize factors in R

I've noticed that the lm function does this automatically with a nice
result.

If I have

group <- c("A", "B","B","C","C","C")

and run:

lm(result ~ x1 + group)

The lm function has split the group into separate binary variables {0,1}
before performing the regression.  I now have:
groupA
groupB
groupC

Some of the other models that I want to try won't accept factors, so
they need to be discretized this way. 

Is there a command in R for this, or some easy shortcut?  (I tried
digging into the lm code, but couldn't find where this is being done.)

Thanks!

-N



More information about the R-help mailing list