Thanks,

That gives me exactly what I'm looking for.

Two quick questions:

1) What would be the fastest way to do this if I have other continuous
data as well.  For example,  I have a data frame with 10 variable and
want to discretize one of them using this method.  (Say, column 6 for
example.)
I thought something like this would work, but it gives me an error:
new.data <- rbind(data[,1:5], model.matrix(~0+data[,6]), data[,7:10])

Error in rbind(deparse.level, ...) :
  numbers of columns of arguments do not match




2) What exactly is it doing?  It appears as if it is a formula similar
to lm, but not actually doing any regression?


Thanks again!

-N


On 5/15/10 11:17 AM, Thomas Stewart wrote:
> Maybe this?
>
> group <- factor(c("A", "B","B","C","C","C"))
> model.matrix(~0+group)
>
> -tgs
>
> On Sat, May 15, 2010 at 2:02 PM, Noah Silverman
> <n...@smartmediacorp.com <mailto:n...@smartmediacorp.com>> wrote:
>
>     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
>
>     ______________________________________________
>     R-help@r-project.org <mailto: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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to