Skip to content
Prev 17287 / 29559 Next

lapply and SpatialGridDataFrame

This should help you get started:

floodfiles <- list.files(pattern=".txt")

maxdepths <- list()
length(maxdepths) <- length(floodfiles)

for(i in seq(along=floodfiles)) {
  cat('-------',i,floodfiles[i],'----------\n')
  maxdepths[[i]] <- readAsciiGrid(floodfiles[i])}

Of course it overwrites. You are assigning the result of readAsciiGrid to
the same object each time.

I believe you would find it helpful to study the basics of R some more.
For example, the difference between [i] and [[i]] is crucial to this
example.

I added the cat() statement so that later on, when something fails as you
loop through the files, it will be obvious which input file had the
problem.

-Don