Problem with recoding new variable to remove categories (NA)

I am relatively new to R but I am using it for my dissertation.

I had a factor variable with multiple categories (treatment outcomes). I wish to combine the categories to create a new variable coded 1, 0. However, I wish to disregard some of the categories I have coded 0 by recoding them to be NA but have had no luck.

-Original variable: COMPLETED, CURED, DEFAULTED, DIEDOTHER, DIEDTB, DIEDUK, FAILED, STILL ON TREATMENT, TRANSFERRED
-Intended new variable:
COMPLETED + CURED = Successful outcomes (1)
DEFAULTED + DIEDTB + FAILED = Unsuccessful outcomes (0)
-What I have done so far:
COMPLETED + CURED = Successful outcomes (1)
DEFAULTED + DIEDOTHER +DIEDTB +DIEDUK +FAILED +STILL ON TREATMENT +TRANSFERRED = Unsuccessful outcomes (0)

R chunk used:
childrendata$outcomenew <- ifelse(childrendata$outcome12months == "COMPLETED"|childrendata$outcome12months == "CURED", 1,0) this has worked
childrendata$outcomenew[childrendata$outcomenew == "DIEDOTHER"|childrendata$outcomenew == "DIEDUK"|childrendata$outcomenew =="STILLONTREATMENT"|childrendata$outcomenew == "TRANSFERRED"] <- NA this didn't alter my numbers to remove these groups
childrendata$outcomenew <- factor(childrendata$outcome12months, levels = c(1, 0), labels = c("Successful", "Unsuccessful")) nor did this, as all my observations became NA

Any help or guidance would be much appreciated.

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.