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.

enter image description here

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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -