From: Kjetil Brinchmann Halvorsen <kjetilbrinchmannhalvorsen_at_gmail.com>

Date: Sat 27 May 2006 - 02:58:48 EST

}

}

} # end indx

}

}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 27 03:07:13 2006

Date: Sat 27 May 2006 - 02:58:48 EST

Hola!

I am programming a class (S3) "symarray" for storing the results of functions symmetric in its k arguments. Intended use is for association indices for more than two variables, for instance coresistivity against antibiotics.

# Storage requirement is given by {r, k}= choose(k, r)

# where r=array rank, k=maximum index

symarray <- function(data=NA, dims=c(1,1)){

r <- dims[1] k <- dims[2] if(r > k) stop("symarray needs dimension larger than array rank") len <- choose(k, r) out <- data[1:len] attr(out, "dims") <- dims class(out) <- "symarray" out

}

# Index calculation:

indx <- function(inds, k){

r <- length(inds)

if(r==1) return(inds) else {

if(inds[1]==1) { return( indx(inds[-1]-1, k-1 ) ) } else { return( indx(c(inds[1]-1, seq(from=k-r+2, by=1, to=k)), k) + indx( inds[-1]-inds[1], k-inds[1] )) }

}

} # end indx

# Methods for assignment and indexing:

"[.symarray" <- function(x, inds, drop=FALSE){

dims <- attr(x, "dims") k <- dims[2] inds <- indx(inds, k) res <- NextMethod("[", x) res

}

"[<-.symarray" <- function(x, inds, value){

dims <- attr(x, "dims") k <- dims[2] inds <- indx(inds, k) res <- NextMethod("[<-", x) res

}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat May 27 03:07:13 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Mon 29 May 2006 - 10:10:26 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*