I have the following array: 3 dimensional object, one dimension being year. Object is 3*3*3
library(plyr, reshape) a1<-rep(c(2007,2008,2009),9) a2<-c(rep("a",9),rep("b",9),rep("c",9)) a3<-c(rep(c(rep(1,3),rep(2,3),rep(3,3)),3)) a4 <- rnorm(27) A<-data.frame(cbind(comp=a2,val=a3, year=a1, a4)) A1<-melt(A, id=c("year", "comp", "val")) A2<-cast(A1, comp~val~year) I would now like to look for changes from one year to the other, i.e. "for(i in levels(A$year)) A2[,,i]-A2[,,i-1]" and put that into A3. Which should work except for the first one, i.e. giving me a 3*3*2 object A3. The more abstract formulation would possibly be cellwise operation within adjacent matrices of the array. I have however searched the forum for the key words and there is not much. Any help even in form of a reference would be appreciated. -- View this message in context: http://www.nabble.com/Subtract-matrices-within-arrays-along-indices-tp24717178p24717178.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.