Skip to content
Prev 105498 / 398506 Next

Count cases by indicator

I might be missing something, but the data you showed don't seem to
match your expectation.  Firstly, 111111111 in binary is 511 in decimal,
so your "coordinates" are off by 1.  Secondly, for the data you've
shown, the matrix equivalent look like:

m <- matrix(df$x, ncol=9, byrow=TRUE)
rownames(m) <- levels(df$cases)
print(m)

         [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
093/0188    0    0    1    0    1    1    1    1    1
093/0206    0    0    0    0    0    0    0    0    0
093/0216    0    1    1    1    1    1    0    1    1
093/0305    0    1    1    1    1    1    1    1    1
093/0325    0    0    0    0    0    0    0    0    0
093/0449    0    0    0    0    0    0    0    0    0
093/0473    0    0    1    1    1    1    1    1    1
093/0499    0    0    1    1    1    1    1    1    1

The counts of unique occurances are:

table(do.call(paste, c(as.data.frame(m), sep="")

000000000 001011111 001111111 011111011 011111111 
        3         1         2         1         1 

which do not agree with yours.

If I understood what you wanted, I would do:

R> table(rowSums(matrix(2^(0:8) * df$x, ncol=9, byrow=TRUE)))

  0 446 500 508 510 
  3   1   1   2   1 

Andy


From: Serguei Kaniovski
------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}