I am working with globally gridded data of annual maximum precipitation. However, I want to isolate those maximum value for land areas "only" for each of my 145 years by using a mask (so 145 maximum values based on all land areas). That said, I am receiving only NA values when I apply the mask, and I cannot understand why (when the mask is not applied, the below procedure works just fine). Here is what I have done so far:
Model66 <- brick("MaxPrecNOAA-GFDLGFDL-ESM2Ghistorical.nc", var="onedaymax")
#Applying the mask to isolate land areas only:
data("wrld_simpl")
b <- wrld_simpl
land <- mask(Model66,b)
#To derive highest maximum value for each layer/year for land only (145 years = 145 maximum values)
Gmax <- sapply(unstack(land), function(r){max(values(r))})
Gmax
[1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA
[40] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA
[79] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
NA NA NA NA NA NA NA
[118] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
Why would this be happening? I isolated land only, and my plots correctly show that the mask worked, as only land has values on the plots for each layer/year (and the idea would be take the highest value among these for each layer/year, as I attempted to do with object "Gmax"). Again, when a mask is not applied, NAs don't show up, so I wonder if it is just a small detail causing this when using the mask?
Any help with this would be greatly appreciated!
Thanks!