Dear listers,

I am trying to create a RasterLayer of the values of a rasterbrick object.
The rasterbrick object has, for example, 100cells

library(raster)
r <- raster(ncol=10, nrow=10)
r[]=1:ncell(r)
s <- brick(r,r,r)
s <- s * 1:3


Each cell of the rasterfinal will have the AREA UNDER CURVE  formed by the
values in each cell of the three original rasters.
For example:
s[4] has the values: 4,8,12

y<-s[4];
x<-0:2;

You can see the AUC in this graph:
plot(x,y, type='l')

And calculate it using the function trapz (package:pracma)
library(pracma)
trapz(x,y)

#################################################################################
My idea was to use 'stackApply':
FINAL<-stackApply(s,1,myFUN)

with:
myFUN=function(y)
{
x<-1:length(y)
trapz(x,y)

}

It doesn´t work. What I am doing wrong??

Many thanks,

	[[alternative HTML version deleted]]

