xuan zhao
2012-Jul-27 17:32 UTC
[R] Turn categorical array into matrix with dummy variables
Hi All, I want to turn a categorical array (array with factors) into a matrix with dummy variables. like array=c(a,a,b,b,b) should be turned into: a b 1 0 1 0 0 1 0 1 0 1 Do you know any way of doing this? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Turn-categorical-array-into-matrix-with-dummy-variables-tp4638134.html Sent from the R help mailing list archive at Nabble.com.
?model.matrix On Fri, Jul 27, 2012 at 11:32 AM, xuan zhao <xuan.zhao@sentrana.com> wrote:> Hi All, > I want to turn a categorical array (array with factors) into a matrix with > dummy variables. like array=c(a,a,b,b,b) should be turned into: > a b > 1 0 > 1 0 > 0 1 > 0 1 > 0 1 > Do you know any way of doing this? > Thanks > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Turn-categorical-array-into-matrix-with-dummy-variables-tp4638134.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]