I am a beginner in R so this is a very basic question. I do not find a specific answer to it so I would like to ask you here.
I'm confronted with the following challenge; I'd like to recode a character variable and create one out of this.
Specifically, the variable in my data frame(data) is called "driver", with the categories "market", "legislation", "technology", and "mixed".
Now I would simply like to create a new variable, "driverrec", with the values "market" and "others". In "others" the three remaining variables shall be summarized.
I tried it with this page: http://rprogramming.net/recode-data-in-r/
Basically, I tried the following code to adopt on mine, but it won't work for more than one category.
#Create a new field called NewGrade
SchoolData$NewGrade <- recode(SchoolData$Grade,"5='Elementary'")
# my attempt
driverrec <- data$driver
recode(driverrec, "'Mixed'='others'") This is working.
But the whole recode is not working:
recode(driverrec, "'Mixed'='others'", "'Technology'='others'",
"'Legislation'='others'", "'Market'='market'" )
I am looking forward to and thank you for your help.
recodeare you using?dplyrorarules? Not sure if they are the same. - NelsonGonrecodefromcar. So probably, you may need to adddplyr::recodeorcar::recodeor else either of them may mask - akrundplyrversion would bedplyr::recode(names(iris), Species='Nope', Sepal.Length='Yep')- NelsonGonfactorswithforcats. Might be easier. - NelsonGon