[R] table problems
David Brahm
brahm at alum.mit.edu
Thu Jun 13 15:49:31 CEST 2002
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)
--
-- David Brahm (brahm at alum.mit.edu)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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