[R] Aggregate
Jim Lemon
bitwrit at ozemail.com.au
Tue Nov 7 13:03:04 CET 2000
Hi Jaget,
If I have correctly understood your problem, this might give you a
start:
sum.response.patterns<-function(mat) {
nrows<-dim(mat)[1]
sorted.mat<-mat[order(mat[,1],mat[,2],mat[,3],mat[,4],mat[,5]),]
pattern.count<-rep(1,nrows)
j<-1
for(i in 1:(nrows-1)) {
if(sum(abs(sorted.mat[i,]-sorted.mat[i+1,])) == 0)
pattern.count[j]<-pattern.count[j]+1
else j<-j+1
}
return(pattern.count[1:j])
}
I tried it with this:
test.mat<-matrix(as.numeric(runif(500) > 0.5),ncol=5)
and it seemed to do what you requested.
You have to use a matrix with this one.
Perhaps one of the experts can get rid of that loop (sigh!)
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list