How to get annual mean for each grid cell in nc4 file

Hello. I'm very very new to coding and R.

I have an nc4 file which has daily precipitation values for the world from 1970 to 1980. I need the annual precipitation values instead of daily. At the end of the day, I would like to draw maps with the annual precipitation values so I should end up with 10 global maps (one for each year).

I don't know if any of this information might be helpful as I am so new to this and all I've done is print the file to see what's inside but I thought some kind soul willing to help me might want to look at this information.

1 variables (excluding dimension variables):
float pr[lon,lat,time]
standard_name: precipitation_flux
long_name: Precipitation
units: kg m-2 s-1
_FillValue: 1.00000002004088e+20
missing_value: 1.00000002004088e+20

 3 dimensions:
    lon  Size:720
        standard_name: longitude
        long_name: longitude
        units: degrees_east
        axis: X
    lat  Size:360
        standard_name: latitude
        long_name: latitude
        units: degrees_north
        axis: Y
    time  Size:3653   *** is unlimited ***
        standard_name: time
        long_name: time
        units: days since 1861-1-1 00:00:00
        calendar: proleptic_gregorian
        axis: T

While I was fiddling around, I did get an error saying cannot allocate vector of size 3.5Gb. Does that mean this file is too big to do anything? Do I need to cut it up?

Thank you so much in advance. My apologies for asking such a basic question but I really didn't know where to start.

The vector size limitation can be tuned if you have sufficient RAM, but I think you have a shorter path. 720x360 is no problem in your geo fields, it's the time field that is bloating the vector.

I suggest that you

  1. Convert time to a datetime object and using lubridate create a vector of 120 data objects (assuming your precip data is monthly)
library(lubridate)
seq(as.Date("1980/1/1"), by = "month", length.out = 120)

You might also consider the sf`` package, which will provide global polygons with projection options in a form of a data frame to which you can attach your data *and* take advantage ofggplot` for visualization. (For color, see my post at https://technocrat.rbind.io/2018/12/03/color-map-atlas-for-continuously-scaled-maps/)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.