[R] creating empty cells with table()

Robin Hankin r.hankin at noc.soton.ac.uk
Wed Apr 19 15:35:05 CEST 2006


Hi

tabulate() approximates your desired functionality:


 > tabulate(c(1,1,1,4,4,4,8,8))
[1] 3 0 0 3 0 0 0 2
 >

(although this works with integer-valued vectors only; it excludes zero
so you might be better to use tabulate(x+1) to catch this)


HTH


Robin


On 19 Apr 2006, at 14:21, Owen, Jason wrote:

> Hello,
>
> Suppose I simulate 20 observations from the Poisson distribution
> with lambda = 4.  I can summarize these values using table() and
> then feed that to barplot() for a graph.
>
> Problem: if there are empty categories (e.g. 0) or empty categories
> within the range of the data (e.g. observations for 6, 7, 9),  
> barplot()
> does not include the empty cells in the x-axis of the plot.  Is there
> any way to specify table() to have specific categories (in the above
> example, probably 0:12) so that zeroes are included?
>
> Thanks,
>
> Jason
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list