On 18/10/19 2:58 PM, Thevaraja, Mayooran wrote:
Hello
You can use the following function,
######################################################
replace_missings <- function(x, replacement) {
is_missings <- is.na(x)
x[is_missings] <- replacement
message(sum(is_missings), " missings replaced by the given value ",
replacement)
x
}
A <- c(0,1,2,3,4,5,6,7,8,9,10)
B <- c(12,15,3,65,NA,12,NA,4,6,25,4)
df <- data.frame(A,B)
replace_missings(df, replacement = 0)
#################################################
The OP wanted to solve the reverse problem. He wanted to replace 8888
by NA, not NA by (e.g.) 8888.
cheers,
Rolf
--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.