[R] Dealing with NaN's in data frames
Muenchen, Robert A (Bob)
muenchen at utk.edu
Sat Aug 16 17:02:13 CEST 2008
Hi Jon,
Here's one way.
> x <- c(1,2,3,4,NaN)
> y <- c(1,2,NaN,4,5)
>
> myDF <- data.frame(x,y)
> myDF
x y
1 1 1
2 2 2
3 3 NaN
4 4 4
5 NaN 5
>
> myDF[ is.na(myDF) ] <- NA
> myDF
x y
1 1 1
2 2 2
3 3 NA
4 4 4
5 NA 5
Cheers,
Bob
=========================================================
Bob Muenchen (pronounced Min'-chen), Manager
Statistical Consulting Center
U of TN Office of Information Technology
200 Stokely Management Center, Knoxville, TN 37996-0520
Voice: (865) 974-5230
FAX: (865) 974-4810
Email: muenchen at utk.edu
Web: http://oit.utk.edu/scc,
News: http://listserv.utk.edu/archives/statnews.html
=========================================================
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Peck, Jon
> Sent: Friday, August 15, 2008 10:28 PM
> To: r-help at r-project.org
> Subject: [R] Dealing with NaN's in data frames
>
> 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