Page 1 of 1

Regarding R version of "ifmiss"

Posted: Wed Mar 02, 2022 6:13 am
by u3517520
First of all, not sure if this is the right forum to post about this, feel free to remove/move to another subforum.

I am trying to move jmv syntax to R.
Sorry this question may be basic, are there R code for the below "ifmiss" function? I am trying to compute such variables in R but couldn't find related function. See attached

Re: Regarding R version of "ifmiss"

Posted: Wed Mar 02, 2022 6:17 am
by jonathon
in R, if you wanted an equivalent to

IFMISS(columnName, ..., ...)

i'd suggest something like:

ifelse(is.na(data$columnName), ..., ...)

cheers

Re: Regarding R version of "ifmiss"

Posted: Wed Mar 02, 2022 7:07 am
by u3517520
jonathon wrote:in R, if you wanted an equivalent to

IFMISS(columnName, ..., ...)

i'd suggest something like:

ifelse(is.na(data$columnName), ..., ...)

cheers
Great, thank you.

Sorry I am unfamiliar ifelse function
So the Jamovi computed variable is IFMISS(P_gain_book, IFMISS(N_nongain_book, IFMISS(N_loss_book, IFMISS(P_nonloss_book, NA,"Book-Negative"),"Book-Negative"),"Book-Positive"),"Book-Positive")"

How to convert that to R using ifelse?

Re: Regarding R version of "ifmiss"

Posted: Thu Mar 03, 2022 4:20 am
by jonathon
so we could rewrite:

IFMISS(P_nonloss_book, NA,"Book-Negative")

as:

ifelse(is.na(data$P_nonloss_book), NA, "Book-Negative")

cheers

Re: Regarding R version of "ifmiss"

Posted: Thu Mar 03, 2022 6:57 am
by u3517520
jonathon wrote:so we could rewrite:

IFMISS(P_nonloss_book, NA,"Book-Negative")

as:

ifelse(is.na(data$P_nonloss_book), NA, "Book-Negative")

cheers
Thank you very much!

I have been making some progress, but encountered an error below.

So what I am trying to do is
If P_gain_book_1 OR P_nongain_book_4 has a value, then the computed variable BookConditionPositiveNegative is "Book-Positive"
If N_nonloss_book_1 OR N_loss_book_1 has a value, then the computed variable BookConditionPositiveNegative is "Book-Negative"
It is a between-subject design.

I tried:
Idsonrepextdatafile$BookConditionPositiveNegative <- ifelse(is.na(Idsonrepextdatafile$P_gain_book_1) | is.na(Idsonrepextdatafile$P_nongain_book_4),NA,"Book-Positive",ifelse(is.na(Idsonrepextdatafile$N_nonloss_book_1) | is.na(Idsonrepextdatafile$N_loss_book_1),NA,"Book-Negative"))

Error:
Error in ifelse(is.na(Idsonrepextdatafile$P_gain_book_1) | is.na(Idsonrepextdatafile$P_nongain_book_4), :
unused argument (ifelse(is.na(Idsonrepextdatafile$N_nonloss_book_1) | is.na(Idsonrepextdatafile$N_loss_book_1), NA, "Book-Negative"))

Re: Regarding R version of "ifmiss"

Posted: Thu Mar 03, 2022 12:24 pm
by MAgojam
Hey @u3517520,
check arguments and parentheses ...
Look at the Rj script of the attached file, maybe it helps you.
Rj-example_ifelse.omv
(2.84 KiB) Downloaded 167 times
Cheers,
Maurizio

Re: Regarding R version of "ifmiss"

Posted: Fri Mar 04, 2022 5:36 am
by u3517520
MAgojam wrote:Hey @u3517520,
check arguments and parentheses ...
Look at the Rj script of the attached file, maybe it helps you.
Rj-example_ifelse.omv
Cheers,
Maurizio
Great, thanks a lot, very much appreciated. It is working now.