[R] creating empty cells with table()

Jim Lemon jim at bitwrit.com.au
Fri Apr 21 01:30:35 CEST 2006


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?
>
The integer.frequency function in the plotrix package (of which there 
will be a new version shortly) handles this, as I couldn't tame either 
tabulate or table to do what I wanted for the "freq" function. Note that 
it is _not_ a highly optimized function.

Jim




More information about the R-help mailing list