[R] Count cases by indicator
Serguei Kaniovski
kaniovsk at wifo.ac.at
Mon Dec 4 10:14:54 CET 2006
Hi,
In the data below, "case" represents cases, "x" binary states. Each
"case" has exactly 9 "x", ie is a binary vector of length 9.
There are 2^9=512 possible combinations of binary states in a given
"case", ie 512 possible vectors. I generate these in the order of the
decimals the vectors represent, as:
cmat<-as.matrix(expand.grid(rep(list(0:1),9)))
cmat<-cmat[nrow(cmat):1,ncol(cmat):1]
"cmat" contains the binary vectors as rows.
QUESTION: I would like to know how often each of the 512 vectors occurs
in "case".
With these data, the output should be a vector with 2^9=512 coordinates,
having 2,2,1,3, as, respectively, the coordinate number 129, 193, 449,
512, and zeros in all other coordinates.
Thank you for your help,
Serguei
df<-read.delim("clipboard",sep=";")
DATA:
case;x
093/0188;0
093/0188;0
093/0188;1
093/0188;0
093/0188;1
093/0188;1
093/0188;1
093/0188;1
093/0188;1
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0206;0
093/0216;0
093/0216;1
093/0216;1
093/0216;1
093/0216;1
093/0216;1
093/0216;0
093/0216;1
093/0216;1
093/0305;0
093/0305;1
093/0305;1
093/0305;1
093/0305;1
093/0305;1
093/0305;1
093/0305;1
093/0305;1
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0325;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0449;0
093/0473;0
093/0473;0
093/0473;1
093/0473;1
093/0473;1
093/0473;1
093/0473;1
093/0473;1
093/0473;1
093/0499;0
093/0499;0
093/0499;1
093/0499;1
093/0499;1
093/0499;1
093/0499;1
093/0499;1
093/0499;1
--
___________________________________________________________________
Austrian Institute of Economic Research (WIFO)
Name: Serguei Kaniovski P.O.Box 91
Tel.: +43-1-7982601-231 Arsenal Objekt 20
Fax: +43-1-7989386 1103 Vienna, Austria
Mail: Serguei.Kaniovski at wifo.ac.at
http://www.wifo.ac.at/Serguei.Kaniovski
More information about the R-help
mailing list