[R] Avoiding loops & apply -function
David Masson
david.masson at env.ethz.ch
Wed Nov 5 15:13:37 CET 2008
I have a question concerning avoiding loops.
I know the function "apply" and I have used it several times, but I feel
blocked
with this situation :
E <- array(X, dim = c(L,nlon,nlat) )
data <- matrix(Y, nrow=nlon, ncol=nlat )
G <- vector(length=L)
for (l in 1:L)
{
G[l] <- function.F(data,E[l,,])
}
- "E" is a 3-dimensional array filled with a given data X.
- "data" is a (nlon*nlat) matrix filled with given data Y.
- "G" is my output vector.
I want to apply the function "function.F", but this function has an
argument that depends
on the index "l" ...
Thanks for your help!
David
More information about the R-help
mailing list