r replace values with na if per column code example
Example 1: r na if
dat <- dat %>% mutate(x = replace(x, x<0, NA))
Example 2: replace any NA in a data frame in r
a = data.frame(a=c(NA,1,2,NA), b=c(1,1,2,NA),c=c(NA,NA,2,NA))
for (i in 1:3){
a[which(is.na(a[,i])),i] = 0
}