I want to get specific specific indicies from the netcdf file to create a 3 dimensional array (and then take the mean of these). However ncvar_get from the R package ncdf4 interprets as additional dimensions and not multiple indicies
library(ncdf4)
# Open NetCDF file (choosing this one as easy to access)
url <- "https://psl.noaa.gov/thredds/dodsC/Datasets/ncep.reanalysis.dailyavgs/surface_gauss/tmax.2m.gauss.2022.nc"
nc <- nc_open(url)
Extract hours 1 to 4, no problem:
# Extract continuous time array
nc_continuous <- ncvar_get(nc, "tmax", start = c(1, 1, 1), count = c(-1, -1, 4))
But actually want just hours 3,5,8,100
# Extract specific non-continuous time indices (3rd, 5th, 8th, 100th)
time_indices <- c(3, 5, 8, 100)
# extract specific times
nc_non_cont <- ncvar_get(nc, var_name, start = c(1, 1, time_indicies), count = c(-1, -1, 1))
Try it on the count side
# extract specific times
nc_non_cont <- ncvar_get(nc, var_name, start = c(1, 1, 1), count = c(-1, -1, time_indicies))
Neither works. I think this is easy but am just using the wrong syntax.