[R] table problems

Jim Lemon bitwrit at ozemail.com.au
Fri Jun 14 14:31:30 CEST 2002


Peter Dalgaard BSA wrote:
> 
> ripley at stats.ox.ac.uk writes:
> 
> > On Thu, 13 Jun 2002, David Brahm wrote:
> >
> > > Robin Hankin <r.hankin at auckland.ac.nz> has a vector of trees visited:
> > >   R> c <- c(3,14,17,22,26,26,17,40,43,25,46,46)
> > > and wants a count of visits for trees 1:50.  table(c) is inadequate because it
> > > omits the zero cases.
> > >
> > > Brian D. Ripley <ripley at stats.ox.ac.uk> suggested:
> > > > Try tabulate(c), which goes to 46.  Or, better,
> > > > tab <- rep(0,50)
> > > > names(tab) <- 1:50
> > > > tab[names(table(c))] <- table(c)
> > >
> > > But tabulate has a second argument (nbins) which does what you want in 1 line:
> > >   R> tabulate(c, 50)
> >
> > Yes if you want 1:50.  Not for other label sets, which is why I did it
> > the more general way.  I did mention tabulate: should have givne more
> > details, I guess.
> 
> My standard device would be
> 
> table(factor(c,levels=1:50))
> 
>
Unless I am mistaken, this looks like the classic "occupancy problem" of
the distribution of R trials into N outcomes. If one wishes to test the
hypothesis that the observed distribution of outcomes differs from the
null-hypothetical distribution (typically that each trial is independent
and the probability of all outcomes is equal) the number of observed
choices must lie in the upper or lower tail for which the cumulative
probability of all values is less than or equal to the alpha for a Type
I error. For the case described, the expected value of choices is 10.76
and the critical value for a single set of trials is 8. Can this really
be done with table()?

Jim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list