Use ?factor
.
See this example
> set.seed(1)
> dummyVariable <- sample(c(0,1), 10, TRUE) # bunch of 0 and 1
> newVariable <- factor(dummyVariable, levels=c(0,1), labels=c("No", "Yes"))
> newVariable # this is now a dummy variable ready for regression analysis
[1] No No Yes Yes No Yes Yes Yes Yes No
Levels: No Yes
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…