Dear R users, Here is my problem:
I have an array with at least four dimensions: > dim(myArray) [1] 20 17 3 6 I'd like to apply a function to each occurrence of the matrix (3x6) defined by the last two dimensions. This interpolation function always return a matrix of the same dimensions as its argument: > interpSecteurs.f(myArray[1, 1, , ]) secteur rotation 1 2 3 4 5 6 1 3 5.25 10 6 6 3 2 3 10.00 10 7 7 3 3 3 0.50 10 8 8 3 But when applying this function with apply, these matrices are coerced in vectors of length 18: > test <- apply(myArray, + c(1, 2), + interpSecteurs.f) > dim(test) [1] 18 20 17 I read in the help that this is the normal behaviour in apply. However, I really need to keep the same dimension as the input data. Do you know any function or method which allows bypassing this behaviour ? (unfortunately my function seems not suitable for a vectorization using sweep) Alternatively, a method to recover the wished array dimensions afterward would be also acceptable. Many thanks in advance. Yves -- --------------------------------------------------- Yves REECHT Dpt STH (Sciences et Technologies Halieutiques) IFREMER, BP 70 29280 PLOUZANE FRANCE tel. +33 (0)2 98 22 43 69 ------------------------------------------)><))))°> [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.