title: How to subset NetCDF files with conditionals in one dimension in R
body: <p>I have a NetCDF file of monthly temperatures that range from 1979 to 2019 with 3 dimensions (lon,lat,time).I dowloaded the file from this website: <a href="https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels-monthly-means?tab=form" rel="nofollow noreferrer">https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels-monthly-means?tab=form</a>. I would like to create a function that allows me to pick all the grid cells with latitudes that are higher than 23 degrees, and for those grid cells just use for example the months December, January, February to calculate annual average. Any ideas will be really appreciated. </p>
  
  <p>So far I just managed to perform the tasks separately but I am looking for more like:</p>
  
  <pre><code>mynetcdf &lt;- 'lake.nc'
  ncFile &lt;- nc_open(mynetcdf)
  lake_temp &lt;- ncvar_get(ncFile,"p0001")
  lon &lt;- ncvar_get(ncFile,"longitude")
  lat &lt;- ncvar_get(ncFile,"latitude")
  time &lt;- ncvar_get)ncFile,"time"
  </code></pre>
  
  <p>I am looking for something like:</p>
  
  <pre><code>if (lat &gt;23) { "set all values in lake_temp to NA except in the months December, January, February"}
  </code></pre>
  
  <p>So far I just managed to subset those months for each year but now I need to incorporate the condition explained above. Thank you so much!</p>