[R] creating empty cells with table()
Romain Francois
francoisromain at free.fr
Wed Apr 19 16:07:40 CEST 2006
Le 19.04.2006 15:21, Owen, Jason a écrit :
> 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
>
Hi,
What about using ?factor with its levels argument :
x <- rpois(30, lambda=4)
table(factor(x,levels=0:12))
Romain
--
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr |
| Doctorant INRIA Futurs / EDF |
+---------------------------------------------------------------+
More information about the R-help
mailing list