Reputation: 1
So I am trying to code gender as a dummy variable. However, the data has gender coded as "1.Male" and "2.Female" (rather than 1=Male and 2=Female) I just want to recode it so it comes out as 1's and 2's
df$men <- car::recode(df$gender_respondent_x, "1=1; 2=0; else=NA")
table(df$men, df$gender_respondent_x, useNA = "ifany")
# 1. Male 2. Female
# <NA> 2845 3069
Upvotes: 0
Views: 50
Reputation: 74
I think extract_numeric()
from tidyr
package is very useful.
library(tidyr)
table(extract_numeric(df$gender_respondent_x))
This function literally extract only digits from strings. I hope you find this helpful. Check out this official document for details.
Upvotes: 0