import multiple files R

Tag: r , csv , raster Author: frdtech88 Date: 2013-10-08

I hope you can help me. I have been trying to import multiple raster datasets into R, recode missing values for each raster data imported, link them to zipcodes and then export each raster data as a csv file with different names. I am trying to use a loop but so far I have only got errors. This is as far as I have gotten (dont laugh):

import all 24 raster datasets

listy<-lapply(file_names,raster, band=1)
names(listy) <- paste0("hour", seq_along(0:23))

so now I have all the raster datasets in a list (listy) and I just need to run the following commands on each one:

example for element 1 of listy

y <- extract(listy$hour1_r, zipcoords)
hour1_zipcode <- cbind(zipid,y)

How can I do this with a loop? I would very much appreciate any suggestions that you may have!

Thank you!!! m

Other Answer1

cant you just do it in a for loop?

for(i in 1:length(listy)) { 

listy[[i]] <- listy[[i]]

or with lapply

lapply(listy, function(x) { 
  x[[i]] <- x[[i]]