Re: [R] Matrix of dummy variables from a factor

From: John Fox <jfox_at_mcmaster.ca>
Date: Wed 07 Dec 2005 - 07:55:37 EST


Dear Charles,

Try model.matrix(~f)[,-1].

Regards,
 John



John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of
> Charles H. Franklin
> Sent: Tuesday, December 06, 2005 3:03 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Matrix of dummy variables from a factor
>
> What is a simple way to convert a factor into a matrix of
> dummy variables?
>

> fm<-lm(y~f)
>
> where f is a factor takes care of this in the estimation. I'd
> like to save the result of expanding f into a matrix for later use.
>
> Thanks.
>
> Charles
>

> --
>
>
> Charles H. Franklin
> Professor, Political Science
> University of Wisconsin, Madison
> franklin@polisci.wisc.edu
> chfrankl@wisc.edu
> 608-263-2022 (voice)
> 608-265-2663 (fax)
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Dec 07 08:41:03 2005

This archive was generated by hypermail 2.1.8 : Wed 07 Dec 2005 - 09:37:33 EST