[R] multidimensional array calculation

Johannes Radinger jradinger at gmx.at
Fri Jan 13 19:28:46 CET 2012


Hello,

probably it is quite easy but I can get it: I have
mulitple numeric vectors and a function using
all of them to calculate a new value:

L <- c(200,400,600)
AR <- c(1.5)
SO <- c(1,3,5)
T <- c(30,365)

fun <- function(L,AR,SO,T){
	exp(L*AR+sqrt(SO)*log(T))
}

How can I get an array or dataframe where
all possible combinations of the factors are listed
and the new value is calculated.

I thought about an array like:
array(NA, dim = c(3,1,3,2), dimnames=list(c(200,400,600),c(1.5),c(1,3,5),c(30,365)))

but how can I get the array populated according to the function?

As I want to get in the end a 2D dataframe I probably will use the melt.array()
function from the reshape package or is there another way to get simple such
a "full-factorial" dataframe with all possible combinations?

Best regards,
Johannes


More information about the R-help mailing list