Regarding R version of "ifmiss"

Discuss statistics related things
Post Reply
u3517520
Posts: 4
Joined: Wed Mar 02, 2022 6:04 am

Regarding R version of "ifmiss"

Post 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
Attachments
Jamovi to R.JPG
Jamovi to R.JPG (123.94 KiB) Viewed 2091 times
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Regarding R version of "ifmiss"

Post by jonathon »

in R, if you wanted an equivalent to

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

i'd suggest something like:

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

cheers
u3517520
Posts: 4
Joined: Wed Mar 02, 2022 6:04 am

Re: Regarding R version of "ifmiss"

Post 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?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Regarding R version of "ifmiss"

Post 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
u3517520
Posts: 4
Joined: Wed Mar 02, 2022 6:04 am

Re: Regarding R version of "ifmiss"

Post 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"))
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: Regarding R version of "ifmiss"

Post 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 151 times
Cheers,
Maurizio
u3517520
Posts: 4
Joined: Wed Mar 02, 2022 6:04 am

Re: Regarding R version of "ifmiss"

Post 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.
Post Reply