[R] Dealing with NaN's in data frames

Gabor Grothendieck ggrothendieck at gmail.com
Sat Aug 16 17:44:48 CEST 2008


Try this:

is.na(DF) <- is.na(DF)

or this which returns a transformed data frame without
overwriting DF:

replace(DF, is.na(DF), NA)

On Fri, Aug 15, 2008 at 10:27 PM, Peck, Jon <peck at spss.com> wrote:
> I am looking for the most efficient way to replace all occurrences of NaN in a data frame with NA.  I can do this with a double loop, but it seems that there should be a higher level and more efficient way.  With is.na, I could use ifelse, but if.nan seems not to have similar capabilities.
>
>
>
> TIA,
>
> Jon Peck
>
>
>
> Jon K. Peck
>
> jkpeck at aya.yale.edu
>
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list