How to write code for ifElse
Dear all, I need some help, I am completely new to this software.
In my survey, I asked people about their main language. Most of the respondents answered by selecting one of the following options: 1. English, 2. Dutch, or 3. French. However, approximately one-quarter of the participants chose "others" and provided the language they spoke. I would like to recode any responses that are not 1. English, 2. Dutch, or 3. French into "Others." Can anyone suggest how I can do that?
I have tried so many times, and it doesn't work.
What I understood so far : ifElse(Language ≠ "1. English" or "2. Dutch" or "3. French", others, _____)
Now sure how to ask the system to remain the original in the last part.
Comments
Hi!
How about this?
If "Other" always has the same capitalization then this should work. Otherwise, it's also possible to use nested `ifElse` statements, but that becomes a bit messy.
Let me know if that solves the issue!
Cheers,
Don
Don, thank you so much. I am really beginner at coding.
Because when my particitpants freely write wahtever language, the words "Other" is not included.
So, what I need to instruct the system to do is, if it is not '1. English,' '2. Dutch,' or '3. French,' then recode it as 'others.'
Any idea how can I tell the system about it ?
Thanks in advance for your help.
MZ
No worries, you can do it like so with the GUI:
But if you ever have many more categories the nested ifelse statements might become a bit cumbersome. You can also write R code directly if you click the R symbol:
and then use the code `result <- ifelse(Column 1 %in% c("1. English", "2. Dutch", "3. French"), as.character(Column 1), "Other")`. Note that I used a Column name with a space in there and you need to type the name exactly like it is shown in jasp in the R code window.
Hope that helps!
Best,
Don