ifElse
I am trying to use the ifelse() function to populate a new column in JASP. If the value in Variable is less than 5 I need the value in newColumn2 to be set to 0, else, it shold be set to 1. It's not clear what goes into the "test" argument. It does not appear to work at all like Excel and I can find no documentation on any of the functions on the far right of this window anywhere on the internet.
A clue on how to search this forum without getting every post with the work ifElse in it would be helpful as well.
Thanks much.
Comments
I'll forward your post to those in the know.
E.J.
Actually, before I call in outside help, did you inspect these resources?
and the gifs listed under https://jasp-stats.org/how-to-use-jasp/
E.J.
Yes, thanks, I did. I couldn't find anything that was specific to the ifelse function. The functions at the top of the window are clear enough (+,-,<,>, etc.) but the ones on the right, in particular ifelse isn't.
I tried running the expression using r code:
ifelse("injuries" > 3,"Yes", "No")
but only the first row gets the computed value. I'm undoubtedly doing something wrong but I don't know enough about r or JASP to figure it out.
OK, that's informative, I'll forward your post.
E.J.
Actually I got the r command to work. Don't know what I was doing before. The expression builder still vexes me. If I can do this with an r function, I'm good but I am curious to see how to expression builder works. Perhaps there's a bug?
Thanks for your help.
Hi Eric,
The builder requires a logical expression in the "test" argument. Here's an example:
In this example, I want a column consisting of 0s and 1s. If Happiness < 4, then it needs to return 0 else a 1. Note that Happiness is a continuous variable, which is why ifelse doesn't take it as an argument. One way around this is as follows:
Alternatively,
Let me know whether this works for you.
Cheers,
Alexander
Hi Eric,
here is a small video contribution ...
Cheers,
Maurizio
Hi Maurizio, are you OK if we add this video to our website and point to it on Twitter?
E.J.
Hi EJ, if you do this, I would be very pleased.
Do it, thank you.
Maurizio
If you'd like some twitter credits you can send your complete name or twitter handle -- otherwise you'll be acknowledged be Maurizio. BTW, do you have this as a gif? (this is the format we generally use)
Hi. This actually does not work in JASP 0.15.0 (Windows 10). It generates an error, as shown below.
R
Hi Richard,
Thanks for reporting this. I've got the same error on mac, so it's safe to assume that it's not platform dependent. I've reported this bug on github see
https://github.com/jasp-stats/jasp-issues/issues/1430
There you can find the jasp file that reproduces the error. It also shows the workaround that does work, namely, temp2, which is created by writing the statement `ifelse(VariableA>2,1,0)` in R code. This is of course not ideal, but it'll be taken into account for the next release, or the one shortly thereafter. Thanks again.
Cheers,
Alexander
In case it is helpful. I have posted the same error message with another dataset here: in the JASP stats github:
ifElse broken in compute column point-and-click interface #1430
I use JASP teaching a large intro applied stats class. I'm not sure how this reporting process goes so thought I'd post both places. I do not teach them R, so the workaround isn't for this group.
JASP is a great program for the students. Happy to figure out how to report errors to make it even better. I especially appreciate the recent capacity to edit figures.
Just waiting for a bar chart with errors (rather than the line graph) but I bet there is somewhere else to go request that.
Thanks,
Paula Marentette
Thanks. We'll have a small release soon (this mainly fixes some installation issues we've been having, and improves things internally) quickly followed by a release with a lot more new functionality.
Cheers,
E.J.