I am having difficulties in R getting climate data from a netCDF file into the right format for further analysis. I am working with gridded global data on Standardized Precipitation Index (downloaded from here and want to aggregate the monthly values for each grid-cells to an annual average.

Now the issue is that in the file the data is organised as TXY, where T are the number of months since January 1960 and X and Y are longitude and latitude respectively. As a result, when I load the file into R with,


I get the following dimensions:

class       : RasterBrick 
dimensions  : 144, 441, 63504, 58  (nrow, ncol, ncell, nlayers)
resolution  : 1, 2.5  (x, y)
extent      : 228, 669, 0, 360  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : data.nc 
names       : X.66.25, X.63.75, X.61.25, X.58.75, X.56.25, X.53.75,... 
degree_north: -66.25, 76.25 (min, max)
varname     : aprod 

So annoyingly, the monthly observations are on the columns whereas the latitude coordinates are on the layers. Which I don't find very useful and makes processing the data rather difficult.

Therefore I wondered, if there is a way in which I can change the dimensions to a more conventional format? With the data of interest on the layers.


That particular data source (IRI data library) allows reordering in its language, e.g. append


data link

  • I didn't dare to venture into Expert Mode. Many thanks. – HorseOfTheYear Oct 22 '15 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.