dear all,

i'm just about to do some straightforward contingency tables using ftables (and 
ctab() for percents).

the problem:
factor "a" are regions, factor "b" are subregions. 
every region "a" consists of some subregions "b", but obviously not every 
subregion "b" is part of every region "a".
if i use the ftable() function, the table contains a lot of zero rows which i 
don't want in my output.

minimal example:

a <- c(1,1,1,1,1,2,2,2,2,2)
> b <- c(4,5,6,5,4,7,8,9,8,7)
> c <- c("a","b","c","d","a","b","b","a","d","d")
> A <- cbind(a,b,c)
> A
      a   b   c  
 [1,] "1" "4" "a"
 [2,] "1" "5" "b"
 [3,] "1" "6" "c"
 [4,] "1" "5" "d"
 [5,] "1" "4" "a"
 [6,] "2" "7" "b"
 [7,] "2" "8" "b"
 [8,] "2" "9" "a"
 [9,] "2" "8" "d"
[10,] "2" "7" "d"
> test <- ftable(a,b,c)
> test
    c a b c d
a b          
1 4   2 0 0 0
  5   0 1 0 1
  6   0 0 1 0
  7   0 0 0 0
  8   0 0 0 0
  9   0 0 0 0
2 4   0 0 0 0
  5   0 0 0 0
  6   0 0 0 0
  7   0 1 0 1
  8   0 1 0 1
  9   1 0 0 0

my question: how can i "delete" the zero rows and preserve the structure and 
attributes of the original table?
 simply doing something like:
test2 <- test[test>0] 
obviously only returns the non-zero values, but not the nice structure and 
attributes of the original table.

to do it by hand is not an option as the original table has like 2000 rows, 
1500 of which are zero...

thanks in advance
marc
______________________________________________________________
"Hostage" mit Bruce Willis kostenlos anschauen!

______________________________________________
R-help@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.

Reply via email to