Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Recode data values in a dataframe into combined values in R

$
0
0

Im trying to compare marital status and my variables have names of "married", "not married", "engaged", "single", and "nota married". How would I make this data only read as "married" and "not married"? (engaged counting as married, single and nota single counting as not married)

Sample dataset

data.frame(mstatus = sample(x = c("married", 
                                  "not married", 
                                  "engaged", 
                                  "single", 
                                  "not married"), 
                            size = 15, replace = TRUE))

This is what I have so far

df2 <- df%>%mutate(
  mstatus = (tolower(mstatus))
)

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>