I have survey data that I have read into my R file. How do I define variables for multiple data points that are meant to be in the same category? I.e. for the Gender column I have: "M", "male", "Male", "Guy", etc. I want to have Male= "M", "male", "Male", "Guy". Thank you for your help in advance!
Asked
Active
Viewed 82 times
-2
-
Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – prosoitos Nov 28 '18 at 18:10
1 Answers
0
Assuming that the column is character
class, we can use %in%
to create a logical index to replace these values with a new one
df1$Col[df1$Col %in% c("M", "male", "Guy")] <- "Male"

akrun
- 874,273
- 37
- 540
- 662