title: How to extract data from thousands of rasters and save into new dataframes
body: <p>I am working with climate data in R, I have 3 folders of raster maps: temperature (tmax,tmin) and precip (RF) - 9131 rasters in each folder, 27393 total.</p>
  
  <p>I need to open each raster and extract data for every Spatial Point (284479 pts) and save the data in a new data.frame.</p>
  
  <p>The goal is to have 284479 files, one for each Spatial Point with the data from each raster in columns (nrows = 9131, ncol = 3).</p>
  
  <pre><code>#Set spatial coordinates to create a Spatial object:
  coordinates(GridPoint) = ~x + y
  Coord &lt;- coordinates(GridPoint)
  
  #Create a loop to generate a input file for each station
  for (i in 1:9131) {
  
  #Open each raster per day of record
  Tmax &lt;- raster(Tmax_asc_files[i])
  Tmin &lt;- raster(Tmin_asc_files[i])
  RF   &lt;- raster(RF_asc_files[i])
  
  #extract Values from each raster for that day
  Tmax_E &lt;- extract(Tmax, Coord)
  tmax.df&lt;- data.frame(Tmax_E)
  
  Tmin_E &lt;- extract(Tmin, Coord)
  tmin.df&lt;- data.frame(Tmin_E)
  
  Prcp_E   &lt;- extract(RF, Coord)
  prcp.df  &lt;- data.frame(Prcp_E)
  
  for (j in 1:length(tmax.df))  {
  
  Cell.matrix &lt;- matrix(nrow = 9131,ncol = 4)
  Cell.matrix &lt;- as.data.frame(Cell.matrix)
  colnames(Cell.matrix) &lt;- c("yearday","tmax","tmin","prcp")
  
  tmax.row &lt;- tmax.df[j,]
  tmin.row &lt;- tmin.df[j,]
  prcp.row &lt;- prcp.df[j,]
  
  #Add date to first column
  Cell.matrix[1] &lt;- Date
  Cell.matrix[i,2:4] &lt;- c(tmax.row, tmin.row, prcp.row)
  
  
  filename &lt;- paste("GridPt_", j, sep = "")
  write.table(Cell.matrix, file = paste(path, filename, ".mtcin", sep = ""),
              row.names = F, quote = F) 
      }
    }
  </code></pre>