Skip to content

Factor contingency tables

2 messages · b k, David Winsemius

#
On Jan 21, 2010, at 12:38 PM, b k wrote:

            
fdf_ghc<- data.frame(AgeDemo=factor( c("26TO35", "36TO45", "46TO55",  
"56TO65", "66TO75", "76TO85") ))
  fdf_ghcnull <- data.frame(AgeDemo= factor( c( "26TO35",  "36TO45",   
"46TO55",  "56TO65",  "66TO75"  ,"76TO85",  "86TO100")  ))

table( rbind(subset(fdf_ghcnull, select=AgeDemo), subset(fdf_ghc,  
select=AgeDemo)) )
# You need a strategy that prevents wiping out the factor level labels.
# in my test case:

  26TO35  36TO45  46TO55  56TO65  66TO75  76TO85 86TO100
       2       2       2       2       2       2       1

Whereas concatenation seemed to remove the factor labels although it  
keeps the counts:
 > factor(c(fdf_ghcnull$AgeDemo, fdf_ghc$AgeDemo))
  [1] 1 2 3 4 5 6 7 1 2 3 4 5 6
Levels: 1 2 3 4 5 6 7
I'm not sure I see how those would accept a single factor or one row  
table for a test.