I have a dataframe that has Nans in some columns. How do I convert the nans in all columns into NAs?
I've tried df[is.nan(df)]<-NA
but it shows this error:
Error in is.nan(df) : default method not implemented for type 'list'
You can do this, if you need to, as explained in this answer by @Hong-Ooi:
is.nan.data.frame <- function(x)
do.call(cbind, lapply(x, is.nan))
df[is.nan(df)] <- NA
Is looks a bit strange, because you are creating a function you are not calling, and this is called Method Dispatch, see the comment by @Hong-Ooi in the answer above.