top of page

Dummy Variables


ds = dataset you are currently using.

DV = dependent variable of interest

IV = independent variable of interest


Subject = name of subject number column 

XYXY = dummy name for a variable, matrix, or data frame into which you are moving information.

First, please note that when running linear regression in R, dummy variables will be created automatically. That said, I have needed to make them from time to time.

Basic command:




To structure it as a data frame:




To integrate the dummy vars into the original data. Note that if you do not want to include the intercept, type the command as "model.matrix(~XYXY$IV)[,c(-1)]))"


XYXY <- data.frame(XYXY, data.frame(model.matrix(~XYXY$IV)))


bottom of page