[R] [FORGED] Re: NA value in list of data frame
Rolf Turner
r@turner @end|ng |rom @uck|@nd@@c@nz
Fri Oct 18 04:38:51 CEST 2019
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
More information about the R-help
mailing list