A unary negative sign with no number is not a number, so it has to be character. If you are done with computations you can format your numbers as character data and set the NA to "-", but such a conversion will prevent you from performing computations so it is only useful for creating report tables.
On June 1, 2021 4:58:38 PM PDT, Kai Yang via R-help <r-help@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@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. -- Sent from my phone. Please excuse my brevity. ______________________________________________ R-help@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.