In the test dataframe below, I am attempting to change every string in the dataframe containing "NA" to "" (so as to make NAs blank).
dat <- as.data.frame(matrix(ncol=2, nrow=2))
dat$V1 <- c(" NA", "foo")
dat$V2 <- c("bar", "NA ")
dat
V1 V2
1 NA bar
2 foo NA
However, the following command returns a completely blank dataframe, as if all strings contained "NA". Why does this happen and what would be the correct solution?
value <- "NA"
dat[grepl(value, dat)] <- ""
dat$V1 <- c(" NA", "NA ")anddat$V2 <- c("foo", "bar ")