How do I convert a categorical value (Yes/No) to numeric value (0/1) in a data set of 20 variables and 3144 observations in R?
(Yes/No)
(0/1)
In R we can either do
R
df1[] <- +(df1=="Yes")
Or
df1[] <- lapply(df1, function(x) as.integer(x=="Yes"))
NOTE: If "Yes" should be 0 and "No" is 1, replace df1=="No" and x=="No" in the post.
df1=="No"
x=="No"
1.4m articles
1.4m replys
5 comments
57.0k users