title: Extract climate data from nc file
body: <p>I am working on a <code>.nc</code> file. The file can be downloaded <code>file size: 35 M</code> <a href="http://cses.washington.edu/rocinante/CMIP5/rcp26/bcc-csm1-1/pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc" rel="nofollow noreferrer">here</a>. I have not worked with <code>nc</code> or <code>raster</code> so much before in R.<br>
  I explored <code>raster</code> package  as well as <code>ncdf4</code> package based on suggestions in different stack answers in other questions. </p>
  
  <pre><code>library(raster)
  library(ncdf4)
  file &lt;- # location to  file you downloaded from the link above
  rfile &lt;- raster(file)
  
  # this is what I got
  
  &gt; rfile
  
  class       : RasterLayer 
  band        : 1  (of  1128  bands)
  dimensions  : 64, 128, 8192  (nrow, ncol, ncell)
  resolution  : 2.8125, 2.789327  (x, y)
  extent      : -1.40625, 358.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
  coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
  data source : D:\STUDY\CMIP5_GCM_month\pr\rcp26\pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc 
  names       : Precipitation 
  z-value     : 2006-01-16 
  zvar        : pr 
  </code></pre>
  
  <p>And I am stuck at this. I don't have an idea how to proceed further. I came across use of <code>@</code> operator but I could not extract something meaningful.</p>
  
  <pre><code>&gt; print(rfile)
  
  File D:\STUDY\CMIP5_GCM_month\pr\rcp26\pr_Amon_bcc-csm1-1_rcp26_r1i1p1_200601-209912.nc (NC_FORMAT_CLASSIC):
  
       4 variables (excluding dimension variables):
          double time_bnds[bnds,time]   
          double lat_bnds[bnds,lat]   
          double lon_bnds[bnds,lon]   
          float pr[lon,lat,time]   
              standard_name: precipitation_flux
              long_name: Precipitation
              comment: at surface; includes both liquid and solid phases from all types of clouds (both large-scale and convective)
              units: kg m-2 s-1
              original_name: PRECC+PRECL
              cell_methods: time: mean (interval: 20 mintues)
              cell_measures: area: areacella
              missing_value: 1.00000002004088e+20
              _FillValue: 1.00000002004088e+20
              associated_files: baseURL: http://cmip-pcmdi.llnl.gov/CMIP5/dataLocation gridspecFile: gridspec_atmos_fx_bcc-csm1-1_rcp26_r0i0p0.nc areacella: areacella_fx_bcc-csm1-1_rcp26_r0i0p0.nc
  
       4 dimensions:
          time  Size:1128   *** is unlimited ***
              bounds: time_bnds
              units: days since 2006-01-01
              calendar: noleap
              axis: T
              long_name: time
              standard_name: time
          lat  Size:64
              bounds: lat_bnds
              units: degrees_north
              axis: Y
              long_name: latitude
              standard_name: latitude
          lon  Size:128
              bounds: lon_bnds
              units: degrees_east
              axis: X
              long_name: longitude
              standard_name: longitude
          bnds  Size:2
  
      27 global attributes:
          institution: Beijing Climate Center(BCC),China Meteorological Administration,China
          institute_id: BCC
          experiment_id: rcp26
          source: bcc-csm1-1:atmosphere:  BCC_AGCM2.1 (T42L26); land: BCC_AVIM1.0;ocean: MOM4_L40 (tripolar, 1 lon x (1-1/3) lat, L40);sea ice: SIS (tripolar,1 lon x (1-1/3) lat)
          model_id: bcc-csm1-1
          forcing: Nat Ant GHG SD Oz Sl SS Ds BC OC
          parent_experiment_id: historical
          parent_experiment_rip: r1i1p1
          branch_time: 2006
          contact: Dr. Tongwen Wu (twwu@cma.gov.cn)
          history: Output from monthly mean data 2011-06-27T08:46:28Z CMOR rewrote data to comply with CF standards and CMIP5 requirements.
          comment: Future projection (2006-2099) forced with prescribed concentration scenario of RCP2.6. The carbon cycle in land and ocean component model is considered, but the time-evolution of CO2 concentration in atmospheric component is prescribed.
          initialization_method: 1
          physics_version: 1
          tracking_id: 93654a27-6561-4263-9ee4-6411ab913c62
          product: output
          experiment: RCP2.6
          frequency: mon
          creation_date: 2011-06-27T08:46:28Z
          Conventions: CF-1.4
          project_id: CMIP5
          table_id: Table Amon (11 April 2011) 1cfdc7322cf2f4a32614826fab42c1ab
          title: bcc-csm1-1 model output prepared for CMIP5 RCP2.6
          parent_experiment: historical
          modeling_realm: atmos
          realization: 1
          cmor_version: 2.5.6
  </code></pre>
  
  <p>The input file is a monthly precipitation data from year 2006 to 2100.<br>
  I need a list containing mean of precipitation for every 10 years interval from <code>2010 - 2020</code>, <code>2021 - 2030</code>, and so on. Can some one guide me on how to do this and where to start from ?</p>