I want all NAs to be replaced with "Not Found" in a df .
i have this df
A B
1 NA
2 NA
3 NA
How can i get that .
A B
1 Not Found
2 Not Found
3 Not Found
You can Assign "Not Found" to df[is.na(df)]. However, it will cause errors if some columns are factors.
df <- data.frame(A = 1:3, B = rep(NA, 3), stringsAsFactors = FALSE)
df
# A B
# 1 1 NA
# 2 2 NA
# 3 3 NA
df[is.na(df)] <- "Not Found"
df
# A B
# 1 1 Not Found
# 2 2 Not Found
# 3 3 Not Found
NAs. Especially if that column is afactor. Other than that, a simple Google search gives all you need. Have you saw this stackoverflow.com/questions/8161836/… ?df$B[is.na(df$B)] <- "Not Found"