Monday, 26 August 2013

How can I convert dummy variables to factors in R?

How can I convert dummy variables to factors in R?

In my data frame (called survey) there is one variable called "answer"
answer
1
2
1
2
I want to convert these dummy variables to
answer
NO
YES
NO
YES
what command should I apply to survey$answer data?
Actually what I want to do is to visualize the data with lattice
barchart(as.factor(with(survey, survey$answer)))
The above command did result in a barchart, but I need to change the
labels to "Yes" and "No" instead of "2" and "1". That's why I need to
convert the dummy variables.

No comments:

Post a Comment