I have a matrix(raster) that I am computing the the mean of each row in this raster as:
library (raster)
r <- raster(nrows=10, ncols=10);r <- setValues(r, 1:ncell(r))
extent(r) = extent(c(xmn=-180,xmx=180,ymn=-90,ymx=90))
stepsize = (r@extent@ymax - r@extent@ymin) / r@nrows
yvals = seq(r@extent@ymax - stepsize / 2, r@extent@ymin, -stepsize)
The x-values will be the mean of each row in the raster:
xvals = rowMeans(as.matrix(r))
plot(xvals, yvals)
What I need is to know how many values were considered when computing the mean for each row (N)? Some pixels may have NA so the number of values will not be the same in each row.
See Question&Answers more detail:os