Hi everyone,
first day in here and already a question. I have a problem quite similar to this:
(SOLVED: Recode variable from text to numbers)
I found that in here on my quest for a solution.
But unlike the original User, my data contains also free text strings, which i want to recode with a certain number. So my Data looks like
but, here's the thing: Bolivia, Togo and some other more exotic Countries should get assigned the Number "3".
I have solved the recoding/mutating part, but i can't find a appropriate expression for "all the rest"=3.
I have tried several if-then-else or dplyr::ifelse constructions, but those didn't work out. Mainly because i'm confused by logical arguments, vectors, data frames and all that stuff.
So, my question is: is there an expression for "all other values" or how can i solve it in another fashion?
I'm quite new to R and RStudio (as you can tell from my question) and i hope helping me isn't too boring...
Best regards
Hi, thanks for trying to provide some properly formatted sample data but you have missed some details to make it actually usable by us, for future reference on how to provide a proper reproducible example, please read the guide on this link
About your problem at hand, you can use the case_when() function from dplyr, see this example (Please notice the way I'm sharing it with you, that would be a proper reprex).