I am relatively new on R. I am trying to get time series of different points ( lat, lon) of temperature data from a netCDF file. My sample data file is here and here is the
Here's how I would proceed to do this with ncdf
:
library(ncdf)
obsdata = open.ncdf("obs1.nc")
obsdatadates = as.Date(obsdata$dim$time$vals,origin = '1950-01-01')
#Get the whole data first
obsoutput = get.var.ncdf(obsdata, varid = 'tasmin')
#Prepare your points of interest
points_of_interest = data.frame(lat=seq(1,8,by=2),lon=c(1,5,3,6))
#Subset your data accordingly
data_at_point = apply(points_of_interest,1,function(x)obsoutput[x[1],x[2],])
#Turn it into a dataframe
data_at_point = as.data.frame(data_at_point)
#Add the dates to the dataframe
data_at_point$Date = obsdatadates