[R] Extracting time-series data from netCDF file for a defined period using ncdf4 package
btupper at bigelow.org
Thu Mar 23 15:12:26 CET 2017
You problem as stated certainly is puzzling since you have one NCDF file but 'time units are different'. I don't know what to make of that.
If you had a simpler case where data are dimensioned as [x,y,t] then you can convert dates to index use in ncdf4::ncvar_get()
I would start with a look-up-table of the dates in the file.
lut <- seq(from = as.Date("1850-01-01"), to = as.Date(Sys.Date()), by = 'day')
The use base::findInterval() to convert your start/stop dates to indices.
mine <- as.Date(c("1971-01-01", "1990-03-01"))
startstop <- findInterval(mine, lut)
Is that at all close to what you seek?
> On Mar 23, 2017, at 6:07 AM, കുഞ്ഞായി kunjaai <dileepkunjaai at gmail.com> wrote:
> Dear All,
> I am trying to extract a time series from a netCDF file.
> I want to extract data for the time period 1971-1 to 1990-12-31 only.
> time axis units is 'days since 1850-1-1'
> For one or two files I can use "count" argument, but I have more than 100
> such files and its time units are different.
> Is there any easy way to extract the particular time period using ncdf4
> Thank you in advance.
> DILEEPKUMAR. R
> J R F, IIT DELHI
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
More information about the R-help