[R] Dealing with NaN's in data frames

Dieter Menne dieter.menne at menne-biomed.de
Sat Aug 16 09:54:18 CEST 2008


Peck, Jon <peck <at> spss.com> writes:

> 
> 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.
 

dt[sample(12,3)] = NaN
df = data.frame(matrix(dt,nrow=3))
df[sapply(df,is.na)] = NA

Dieter



More information about the R-help mailing list