[R] Basic Dummy Variable Creation

Francisco J. Bido bido at mac.com
Fri Sep 5 15:31:59 CEST 2003

Hi There,

While looking through the mailing list archive, I did not come across a 
simple minded example regarding the creation of dummy variables.  The 
Gauss language provides the command "y = dummydn(x,v,p)" for creating 
dummy variables.

x = Nx1 vector of data to be broken up into dummy variables.
v = Kx1 vector specifying the K-1 breakpoints
p = positive integer in the range [1,K], specifying which column should 
be dropped in the matrix of dummy variables.
y = Nx(K-1) matrix containing the K-1 dummy variables.

My recent mailing list archive inquiry has led me to examine R's 
"model.matrix" but it has so many options that I'm not seeing the 
forest because of the trees.  Is that really the easiest way? or is 
there something similar to the dummydn command described above?

To provide a concrete scenario, please consider the following.  Using 
the above notation, say, I had:

x <- c(1:10)      #data to be broken up into dummy variables
v <- c(3,5,7)     #breakpoints
p =  1                #drop this column to avoid dummy variable trap

How can I get a matrix "y" that has the associated dummy variables for 
Thank You,

More information about the R-help mailing list