I have a dataset consisting of lon, lat and a monthly mean variable (e.g. temperature or precipitation) covering 1961 to 1970. The dataset is at a resolution of 0.5 by 0.5 degree lon/lat and covers the whole globe and was downloaded as an .NC file which I have extracted the data in R by using:
library(ncdf)
f <- open.ncdf("D:/CRU/cru_ts3.21.1961.1970.tmp.dat.nc")
A <- get.var.ncdf(nc=f,varid="tmp")
B <- get.var.ncdf(nc=f,varid="lon")
C <- get.var.ncdf(nc=f,varid="lat")
D <- cbind(expand.grid(B, C))
E <- expand.grid(A)
The expanded grid (E) is a data table consisting of 31,104,000 rows of the variable and the expanded grid (D) is a data table consisting of 259,200 rows of lon/lat. If you multiply 259,200 * 10 years * 12 months you get the 31,104,000. Hence the table E can be chopped up into monthly values by using:
Month <- 1
Start <- (Month-1)*(259200)+1
Finish <- (Month*259200)
G <- E[Start:Finish,]
H <- expand.grid(G)
I <- cbind(D,H)
Therefore I is now a data table of the first month (i.e. January 1961) consisting of lon, lat and the variable. An example of the data is given below:
lon lat tmp
49184 -68.25 -55.75 7.5
49185 -67.75 -55.75 7.6
49186 -67.25 -55.75 7.6
49899 -70.75 -55.25 6.8
49900 -70.25 -55.25 7.0
49901 -69.75 -55.25 6.9
49902 -69.25 -55.25 7.1
49903 -68.75 -55.25 6.8
49904 -68.25 -55.25 7.6
49905 -67.75 -55.25 8.2
Now for my question. The current resolution of the grid is 0.5 * 0.5 degrees, and I would like to "regrid" the data so the resolution is 0.25 * 0.25 degrees. I don't want to do anything particularly clever with the data, so I just want the 0.25 grid to take the value of the 0.5 grid that it sits in i.e. each 0.5*0.5 grid contains 4 0.25*0.25 grids and I just want the 4 0.25*0.25 grids to have the same value as the 0.5*0.5 grid.
I've looked at raster but don't seem to be able to do anything with it.