[R] Aggregate
Jonathan Rougier
J.C.Rougier at durham.ac.uk
Wed Nov 8 12:44:05 CET 2000
Hi Jim,
On Wed, 8 Nov 2000, Jim Lemon wrote:
> 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])
> }
>
> So, this morning I have fooled around trying to get something like I
> would expect from an UNIX 'sort' function and, while I have gotten the
> argument list as a character string:
>
> paste(paste("mat[,",1:dim(mat)[2],"]",sep="")sep=",",collapse="")
>
> I have drawn a blank on how to make this into an argument list. Might I
> beg assistance?
Perhaps simpler than the solution you subsequently posted would be
oo <- do.call("order", split(mat, col(mat)))
sorted.mat <- mat[oo, ]
As for your loop, it seems to me that the object you should be processing
is
sad <- apply(abs(sorted.mat[-nrow(sorted.mat), , drop=FALSE] -
sorted.mat[-1, , drop=FALSE]), 1, sum) == 0
Cheers, Jonathan.
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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