[R] convert factor to indicator matrix

Rolf Turner r.turner at auckland.ac.nz
Thu Jul 2 00:10:53 CEST 2009


On 2/07/2009, at 9:53 AM, Thomas Mang wrote:

> Hi,
>
> I am looking for a function which can convert a single factor (a
> vector), or a list of multiple factors, into the indicator (dummy)
> matrix with 0/1 entries (or other contrasting schemes). I could  
> cook it
> myself, but I am actually sure this thing already exists - but forgot
> the name and package. IIRC it was clearly different from model.matrix,
> because it had a nicer, more straightforward interface [I know how to
> use model.matrix. I just can't figure out the other function any  
> more].

It seems to me that

	m <- model.matrix(~x)

(where x is your factor) is pretty straightforward.  How much simpler
can it get?  The power of the formula concept is working for you here;
it would be hard to do without it.

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}




More information about the R-help mailing list