[R] table problems

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Jun 13 16:51:59 CEST 2002


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.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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