[R] NaN - trouble fixing NaN

William Dunlap wdunlap at tibco.com
Mon Apr 2 17:28:08 CEST 2012


Also, mean(x) will generate NaN's if both Inf and -Inf are in x.  E.g.,

  > group <- c("A","A","A",  "B","B","B",  "C","C",  "D","D")
  > when <-  c(      1,2,3,   -Inf,4,Inf,     NA,5,    NaN,6)
  > tapply(when, group, mean)
    A   B   C   D 
    2 NaN  NA NaN 
  > tapply(when, group, mean, na.rm=TRUE)
    A   B   C   D 
    2 NaN   5   6

boxplot() tosses out the +-Inf's.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of R. Michael Weylandt
> Sent: Monday, April 02, 2012 6:19 AM
> To: Jhope
> Cc: r-help at r-project.org
> Subject: Re: [R] NaN - trouble fixing NaN
> 
> Without seeing data, it's only a guess, but you should pass na.rm =
> TRUE to mean() so it will pass over NaNs in the data :
> 
> tapply(HSuccess, Aeventexhumed, mean, na.rm=TRUE)
> 
> Cheers,
> Michael
> 
> On Sun, Apr 1, 2012 at 7:27 PM, Jhope <jeanwaijang at gmail.com> wrote:
> > Hi R-listers,
> >
> > I am using the package plyr. I am just trying to get the hatching success
> > mean of each nesting event and have typed in the following and received the
> > below results:
> >
> >> tapply(HSuccess, Aeventexhumed, mean)
> >        A                    B                  C
> > 0.2156265 0.1288559       NaN
> >
> > What can I do about NaN? I should be able to get a result for event C
> > because I was able to make a boxplot graph with this information showing all
> > three nesting events (A, B, and C).
> >
> > Please advise,
> >
> > Jean
> >
> > --
> > View this message in context: http://r.789695.n4.nabble.com/NaN-trouble-fixing-NaN-
> tp4524713p4524713.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
> 
> ______________________________________________
> 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