From: Huntsinger, Reid <reid_huntsinger_at_merck.com>

Date: Sat 30 Apr 2005 - 06:35:15 EST

pager gheine@my2way.com

*<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>t
*

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

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 Apr 30 06:39:47 2005

Date: Sat 30 Apr 2005 - 06:35:15 EST

Say you have a function FUN of two vector arguments which operates
"columnwise on arrays". E.g., if FUN(v,w) is to be the inner product, then
instead of v%*%t(w) write something like colSums(v*w). Now you can do
something like

vectorOuterProd <- function(A,B,FUN) {

da <- dim(A)[-1] na <- prod(da) db <- dim(B)[-1] nb <- prod(db)

result <- matrix(nrow=na,ncol=nb)

dim(B) <- c(dim(B)[1],nb)

for (j in 1:nb) {

result[,j] <- FUN(A,B[,j])

}

dim(result) <- c(da,db)

result

}

which loops over the columns of B rather than replicate A and B as in outer() to save space.

Is there available in R a generalized inner product or matrix product, similar to 'outer(x,y, fun)', where one can specifiy an arbitrary function in place of ordinary multiplication?

"please rate your skill in task X", and other questions of the form

"Have you taken course Y?" (or "How many years since you have taken course Y?")

Is there a way to accomplish this without nested 'for' statements?

Hope this is clear - thanks!

*<>=<>=<>=<>=<>=<>=<>=<>=<>=<>=<>
*

George Heine, PhD

Mathematical Analyst

National IRM Center

U.S. Bureau of Land Management

voice (303) 236-0099

fax (303) 236-1974 cell (303) 905-5382

pager gheine@my2way.com

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

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 Apr 30 06:39:47 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:31 EST
*