# [R] Aggregate

Jim Lemon bitwrit at ozemail.com.au
Tue Nov 7 23:51:27 CET 2000

```Apologies for this extended correspondence with myself.  I worked out
another solution.

binvec2dec<-function(binvec) {
result<-0
for(i in 1:length(binvec)) result<-result+binvec[i]*2^i
return(result)
}
sum.response.patterns<-function(mat) {
matdim<-dim(mat)
sorted.mat<-mat[order(apply(mat,1,binvec2dec)),]
sorted.mat<-cbind(sorted.mat,rep(1,matdim[1]))
print(sorted.mat)
j<-1
rindex<-1:matdim[2]
count.index<-matdim[2]+1
for(i in 1:(matdim[1]-1)) {
if(sum(abs(sorted.mat[i,rindex]-sorted.mat[i+1,rindex])) == 0)
sorted.mat[j,count.index]<-sorted.mat[j,count.index]+1
else {
j<-j+1
sorted.mat[j,]<-sorted.mat[i+1,]
}
}
return(sorted.mat[1:j,])
}

I do hope that this is the right answer...

Jim

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```