try this:

dat <- data.frame(x = rnorm(10), y = rnorm(10),
    z = rnorm(10), g = gl(5,2))
dat$x[sample(10, 3)] <- NaN
dat$y[sample(10, 3)] <- NaN
dat$z[sample(10, 3)] <- NaN

dat[] <- lapply(dat, function(x){
    x[is.nan(x)] <- NA
    x
})


I hope it helps.

Best,
Dimitris

Peck, Jon 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

[EMAIL PROTECTED]


        [[alternative HTML version deleted]]

______________________________________________
R-help@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.



--
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://perswww.kuleuven.be/dimitris_rizopoulos/



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

______________________________________________
R-help@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.

Reply via email to