How can I convert dummy variables to factors in R? -
in data frame (called survey) there 1 variable called "answer"
answer 1 2 1 2
i want convert these dummy variables
answer no yes no yes
what command should apply survey$answer data?
actually want visualize data lattice
barchart(as.factor(with(survey, survey$answer)))
the above command did result in barchart, need change labels "yes" , "no" instead of "2" , "1". that's why need convert dummy variables.
use factor
function in:
> answer <- c(1,2,1,2) > answer <- factor(answer, labels=c("no", "yes")) [1] no yes no yes levels: no yes
Comments
Post a Comment