Skip to content
Prev 389014 / 398506 Next

How to globally convert NaN to NA in dataframe?

`data[sapply(data, is.nan)] <- NA` is a nice compact command, but I
still get NaN when using the summary function, for instance one of the
columns give:
```
Min.   : NA
1st Qu.: NA
Median : NA
Mean   :NaN
3rd Qu.: NA
Max.   : NA
NA's   :110
```
I tried to implement the second solution but:
```
df <- lapply(x, function(xx) {
  xx[is.nan(xx)] <- NA
})
List of 1
 $ sd_ef_rash_loc___palm: logi NA
```
What am I getting wrong?
Thanks
On Thu, Sep 2, 2021 at 3:30 PM Andrew Simmons <akwsimmo at gmail.com> wrote: