Message-ID: <CAMk+s2RFnye1D3ncRy6FAxKsrbMF7c3mZ54JBPra6WYFoP6qgg@mail.gmail.com>
Date: 2021-09-02T13:18:13Z
From: Luigi Marongiu
Subject: How to globally convert NaN to NA in dataframe?
Hello,
I have some NaN values in some elements of a dataframe that I would
like to convert to NA.
The command `df1$col[is.nan(df1$col)]<-NA` allows to work column-wise.
Is there an alternative for the global modification at once of all
instances?
I have seen from
https://stackoverflow.com/questions/18142117/how-to-replace-nan-value-with-zero-in-a-huge-data-frame/18143097#18143097
that once could use:
```
is.nan.data.frame <- function(x)
do.call(cbind, lapply(x, is.nan))
data123[is.nan(data123)] <- 0
```
replacing o with NA, but I got
```
str(df)
> logi NA
```
when modifying my dataframe df.
What would be the correct syntax?
Thank you
--
Best regards,
Luigi