Skip to content
Prev 276317 / 398506 Next

query about counting rows of a dataframe

On Nov 3, 2011, at 12:28 PM, Stefano Sofia wrote:

            
xtabs sometimes give better results. If you want all 31 days then make  
day_birth a factor with levels=1:31)

 > xtabs(  ~ day_birth + month_birth + year_birth, data=dat)
, , year_birth = 2001

          month_birth
day_birth 10 11 12 13 14
        1   0  1  0  0  0
        3   0  2  0  0  0
        4   0  2  0  0  0
        5   0  0  1  0  0
        22  1  0  0  0  1
        29  1  0  0  1  0
Cannot figure out what is being asked here. What to do with the two  
values? Just count them? This would give a partitioned count

 > xtabs( labour==1 ~ day_birth + month_birth , data=dat)
          month_birth
day_birth 10 11 12 13 14
        1   0  1  0  0  0
        3   0  1  0  0  0
        4   0  1  0  0  0
        5   0  0  0  0  0
        22  1  0  0  0  0
        29  0  0  0  0  0
 > xtabs( labour==2 ~ day_birth + month_birth , data=dat)
          month_birth
day_birth 10 11 12 13 14
        1   0  0  0  0  0
        3   0  1  0  0  0
        4   0  1  0  0  0
        5   0  0  1  0  0
        22  0  0  0  0  1
        29  1  0  0  1  0
If I understand correctly:

 > xtabs(  ~ day_birth + month_birth + year_birth, data=dat)
, , year_birth = 2001

          month_birth
day_birth 10 11 12 13 14
        1   0  1  0  0  0
        3   0  2  0  0  0
        4   0  2  0  0  0
        5   0  0  1  0  0
        22  1  0  0  0  1
        29  1  0  0  1  0
Again confusing. Do you mean to use separate tables for labour==1 and  
labour==2? Perhaps context to explain what these values represent.  
Some of us are "concrete". The results of xtabs are tables and can be  
divided like matrices.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT