[R] How to globally convert NaN to NA in dataframe?

Greg Minshall m|n@h@|| @end|ng |rom um|ch@edu
Thu Sep 2 21:20:56 CEST 2021


Andrew,

> x[] <- lapply(x, function(xx) {
>     xx[is.nan(xx)] <- NA_real_
>     xx
> })
> 
> is different from
> 
> x <- lapply(x, function(xx) {
>     xx[is.nan(xx)] <- NA_real_
>     xx
> })

indeed, the two are different -- but some ignorance of mine is exposed.
i wonder, can you explain why the two are different?

is it because of (or, "is the clue...") this in the "Value:" section of
: ?"[<-.data.frame"
----
     For '[<-', '[[<-' and '$<-', a data frame.
----
?

cheers, Greg



More information about the R-help mailing list