[R] Showing zero frequencies with xtabs

Luca Meyer lucam1968 at gmail.com
Tue Aug 30 15:46:36 CEST 2011


Thanks Peter & Petr,

It was indeed an issue of having some character variables in there. Now it works just fine.

Cheers,
Luca

Il giorno 30/ago/2011, alle ore 10.15, peter dalgaard ha scritto:

> 
> On Aug 30, 2011, at 10:04 , Luca Meyer wrote:
> 
>> Hi,
>> 
>> Does anyone know how to show zero frequencies variable levels with the xtabs command? They show with the table(x,y) command but I need to apply weight to frequency tables and I also need to cbind several tables together, which implies that they all need to show the same number of rows. 
> 
> Are you sure you are doing the same thing as with table(). I'd expect it to work if you ensure that the variables are factors:
> 
>> library(ISwR)
>> xtabs(~sex+menarche,data=juul)
>   menarche
> sex   1   2
>  2 369 335
> 
>> juul$sex <- factor(juul$sex,levels=1:2)
>> xtabs(~sex+menarche,data=juul)
>   menarche
> sex   1   2
>  1   0   0
>  2 369 335
> 
> 
> 
>> 
>> Alternatively, do you know how to column bind tables with different number of rows? I cannot use merge as it requires daata.frame and that modifies the look of the banner table I am trying to create...
>> 
>> Thanks,
>> Luca
>> 
>> 
>> Mr. Luca Meyer
>> www.lucameyer.com
>> R version 2.13.1 (2011-07-08)
>> Mac OS X 10.6.8
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help a r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> -- 
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes a cbs.dk  Priv: PDalgd a gmail.com
> 



More information about the R-help mailing list