[R] data manipulation question

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Aug 24 02:19:34 CEST 2021

Hi Kai,
How about setting:

germlinepatients$DisclosureStatus <- NA

then having your three conditional statements as indices:

== 1] <-"DISCLOSED"
gl_resultsdisclosed == 0] <- "ATTEMPTED"
 germlinepatients$DisclosureStatus[is.na(germlinepatients$gl_resultsdisclosed) &
 germlinepatients$gl_discloseattempt1 != "ATTEMPTED"] <-"ATTEMPTED"

I know it's not elegant and you could join the last two statements
with OR (|) but it may work.


On Tue, Aug 24, 2021 at 9:22 AM Kai Yang via R-help
<r-help using r-project.org> wrote:
> Hello List,
> I wrote the script below to assign value to a new field DisclosureStatus.
> my goal is if gl_resultsdisclosed=1 then DisclosureStatus=DISCLOSED
> else if gl_resultsdisclosed=0 then DisclosureStatus= ATTEMPTED
> else if gl_resultsdisclosed is missing and gl_discloseattempt1 is not missing then DisclosureStatus= ATTEMPTED
> else missing
> germlinepatients$DisclosureStatus <-
>               ifelse(germlinepatients$gl_resultsdisclosed==1, "DISCLOSED",
>                 ifelse(germlinepatients$ gl_resultsdisclosed==0, "ATTEMPTED",
>                    ifelse(is.na(germlinepatients$gl_resultsdisclosed) & germlinepatients$gl_discloseattempt1!='', "ATTEMPTED",
>                                                            NA)))
> the first 3 row give me right result, but the 3rd row does not. After checking the data, there are 23 cases are gl_resultsdisclosed is missing and gl_discloseattempt1 is not missing.  the code doesn't has any error message.
> Please help
> thank you
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list