Replace NA values from a column with 0 in data frame R [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Set NA to 0 in R I have a data.frame with a column having NA values. I want to replace NA with 0 or any other value. I have tried a lot of threads and methods but it did not give me the result. I have tried the below methods. a$x[a$x==NA]<-0; a[,c("x")]<-apply(a[,c("x")],1,function(z){replace(z, is.na(z), 0)}); a$x[is.na(a$x),]<-0; None of the above methods replaced NA with 0 in column x for data.frame a . Why?