title: Reduce daily data to monthly using Google Earth Engine
body: <p>I am looking at precipitation data (both <a href="https://explorer.earthengine.google.com/#detail/NASA%2FGPM_L3%2FIMERG_V05" rel="nofollow noreferrer">GPM</a> and <a href="https://explorer.earthengine.google.com/#detail/UCSB-CHG%2FCHIRPS%2FDAILY" rel="nofollow noreferrer">CHIRPS</a>) for different provinces in Indonesia using Google Earth Engine. GPM is sub-daily (every 30 minutes) and CHIRPS is daily. I am only interested in getting the monthly values. Unlike <a href="https://gis.stackexchange.com/questions/258344/reduce-image-collection-to-get-annual-monthly-sum-precipitation">here</a> and <a href="https://gis.stackexchange.com/questions/279622/writing-code-for-monthly-ndvi-medians-in-google-earth-engine">here</a> I am not interested in getting the multi-annual monthly values, but simply the average of each month and make a time series.</p>
  
  <p><a href="https://gis.stackexchange.com/questions/272169/how-to-download-monthly-values-for-a-time-series-ncep-re-surface-temp-in-gee">Here</a> I found a way to create a list of values containing the mean of each month.</p>
  
  <p>Edit: Thanks to Nicholas Clinton's <a href="https://stackoverflow.com/questions/51710608/reduce-daily-data-to-monthly-using-google-earth-engine/51716560#51716560">answer</a> I managed to get it to work:</p>
  
  <pre><code>var fc = ee.FeatureCollection('ft:1J2EbxO3zzCLggEYc57Q4mzItFFaaPCAHqe1CBA4u') // Containing multiple polygons
      .filter(ee.Filter.eq('name', 'bangka')); // Here I select my ROI
  
  Map.addLayer(fc, {}, 'area');
  Map.centerObject(fc, 7);
  
  var aggregate_array = fc.aggregate_array('name');
  print('Name of area: ', aggregate_array, 'Selected data in FeatureCollection:', fc);
  
  var month_mean = ee.List.sequence(0, 16*12).map(function(n) { // .sequence: number of years from starting year to present
    var start = ee.Date('2002-01-01').advance(n, 'month'); // Starting date
    var end = start.advance(1, 'month'); // Step by each iteration
  
    return ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY")
          .filterDate(start, end)
          .mean()
          .set('system:time_start', start.millis());
  });
  print(month_mean); 
  
  var collection = ee.ImageCollection(month_mean);
  
  print(collection);
  
  // Plotting
  
  var area_name = fc.aggregate_array('name').getInfo();
  var title = 'CHIRPS [mm/hr] for ' + area_name;
  
  var TimeSeries = ui.Chart.image.seriesByRegion({
      imageCollection: collection,
      regions: fc,
      reducer: ee.Reducer.mean(),
      scale: 5000,
      xProperty: 'system:time_start',
      seriesProperty: 'label'
    }).setChartType('ScatterChart')
      .setOptions({
        title: title,
        vAxis: {title: '[mm/hr]'},
        lineWidth: 1,
        pointSize: 1,
      });
  
  print('TimeSeries of selected area:', TimeSeries);
  </code></pre>