Skip to content

Matrix of dummy variables from a factor

3 messages · Charles H. Franklin, John Fox, Uwe Ligges

#
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
#
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 
--------------------------------
#
Charles H. Franklin wrote:

            
model.matrix(y~f)

Uwe Ligges