[R] replace NA into - for specific column
konstantinos christodoulou
kon@t@nt|no@@chr|@todou|ou1 @end|ng |rom gm@||@com
Wed Jun 2 11:25:57 CEST 2021
Hi Kai,
You can also try this:
proband_crc2 %>%
mutate(MMR = replace(MMR, MMR =="NA", "-"))
Thanks,
Kostas
On Wed, Jun 2, 2021 at 11:59 AM Jim Lemon <drjimlemon using gmail.com> wrote:
> Hi Kai,
> Maybe this will help:
>
> proband_crc2<-data.frame(MMR=rep(c(NA,"+"),3))
> proband_crc2
> proband_crc2$MMR[is.na(proband_crc2$MMR)]<-"-"
> proband_crc2
>
> Jim
>
> On Wed, Jun 2, 2021 at 9:59 AM Kai Yang via R-help <r-help using r-project.org>
> wrote:
> >
> > Hi List,
> > I have a column MMR in a data frame proband_crc2. The column contents
> missing value and + (means positive).
> > I need to replace all missing value into - (means negative)
> > I did try with difference ways. Below are my testing, but not any one
> works. Can someone help me?
> > Thanks,
> > Kai
> > proband_crc2 %>% mutate(MMR=recode(MMR, '' = "-"))
> > proband_crc2 <- data.frame (ifelse(proband_crc2$MMR !="+",
> "-", NA))
> > proband_crc2$MMR <- ifelse(MMR %in% c(""," ","-"), NA, MMR)
> > proband_crc2$MMR[proband_crc2$MMR==NA] <- "-"
> > proband_crc2 <- data.frame( proband_crc2 %>%
> mutate(across(c("MMR"), ~ifelse(.==NA, "-", as.character(.)))))
> >
> >
> > [[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.
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list