1

Unfortunately as I dont have enough reputation (and cannot comment on that topic) I have to ask a simple question to an already existing problem. I was computing a raster mosaic in R and stuck to this process: How can I create raster mosaic using list of rasters? (Thanks a lot for that!).

My only problem is, that I want to compute it either using the median or mean but exluding my NAs. I am sorry but I didn't manage to include it into the existing code:

b1_listargs <- b1_unstack
b1_listargs$fun <- mean
b1_mosaic <- do.call(mosaic, b1_listargs)

As I understand the function from above it doesn't exclude NAs automatically. So given the mean of c(4,4,4,4,NA) my computed value would turn out to be NA - that's not useful to me as an output...

Thanks for your help!

Community
  • 1
  • 1
user2978751
  • 57
  • 1
  • 10

2 Answers2

0

Look at this page : http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/mosaicplot.html

It shows that there is an argument to omit NAs.

Nedinator
  • 1,052
  • 13
  • 24
  • I dont want to plot the mosaic but generate it. As I have a lots of layers I stuck to the code above. A simple `mosaic(b1_unstack,fun=mean, na.rm=TRUE)` is not possible as `b1_unstack` is a list and the mosaic command doesn't accept lists anymore - according to the link from above. Thats why I had to stick to this code sample and want to somehow include the `na.rm=T`. – user2978751 Jan 15 '15 at 14:58
  • Have you tried simply doing na.omit(yourmosaic) in its own line? – Nedinator Jan 15 '15 at 15:03
  • As I understand the process the mosaic is being computed from some other layers. I can use functions like `mean` and `median` to get the values for the mosaic (derived by the many other layers). My goal is to exclude NAs already in this computing process (`mean` with NA is different to `mean` without NA). I think your function just applies to the removal of NAs of an already existing/computed mosaic. – user2978751 Jan 15 '15 at 15:09
  • As I understand the function from above it doesn't exclude NAs automatically. So given the `mean` of `c(4,4,4,4,NA)` my computed value would turn out to be `NA` - that's not useful to me as an output... – user2978751 Jan 16 '15 at 09:51
0

I know the question is a bit old, but I am in the same situation and I will try:

where "A" is my list of rasters

A$fun <- mean
Mosaic <- do.call(mosaic, list(A,na.rm=T))

This should ignore the missing values when calculating the mean between overlapping rasters.

MercedesRD
  • 21
  • 3