[R] replace NA into - for specific column

Kai Yang y@ngk@|9999 @end|ng |rom y@hoo@com
Wed Jun 2 01:58:38 CEST 2021

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?
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]]

More information about the R-help mailing list