library(rgdal) my_asc=dir("~/Pulpit/dods/karol/TVDI 113_121",pattern=".asc",recursive=T,full.names=T) for (i in 1:length(my_asc)) { r <- readGDAL(my_asc[i]) z <- as.matrix(r) vectordata[i] <- mean(z) vectordatamax[i] <- max(z) vectordatamin[i] <- min(z) vectordev[i] <- sd(z,na.rm=True) hist(z) png(filename="hist"+tostring(i)+".png") } <li>I try to do some modyfication of this loop, but it still doesn't works - which fragment is incorrect? <li>I would like also to use more complicated pattern (to list only files which contains on the end of it name two numbers), but adding something like: pattern="_??.asc" seems not works. <li>I would like to add one more loop to get list of folders (instead of manually inserting directories into my_asc variable), but I haven't got Idea how I can do it? <li>I do not know, why my way of creating vectors for mean, max, min and standard deviation values is not working... -- View this message in context: http://r.789695.n4.nabble.com/R-problem-with-my-loops-which-operate-on-raster-data-tp3497533p3497533.html Sent from the R help mailing list archive at Nabble.com.
Michael Sumner
2011-May-05 08:51 UTC
[R] R - problem with my loops which operate on raster data
Stackoverflow users have attempted to help you improve your question - please don't ignore advice this with an undeclared cross-post here: http://stackoverflow.com/questions/5892548/problem-with-loops-in-r For this list "PLEASE do read the posting guide http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code." Cheers, Mike. On Thu, May 5, 2011 at 2:21 PM, mateokkk <vkedzior@is.pw.edu.pl> wrote:> library(rgdal) > my_asc=dir("~/Pulpit/dods/karol/TVDI > 113_121",pattern=".asc",recursive=T,full.names=T) > for (i in 1:length(my_asc)) > { > r <- readGDAL(my_asc[i]) > z <- as.matrix(r) > vectordata[i] <- mean(z) > vectordatamax[i] <- max(z) > vectordatamin[i] <- min(z) > vectordev[i] <- sd(z,na.rm=True) > hist(z) > png(filename="hist"+tostring(i)+".png") > } > > <li>I try to do some modyfication of this loop, but it still doesn't works > - > which fragment is incorrect? > <li>I would like also to use more complicated pattern (to list only files > which contains on the end of it name two numbers), but adding something > like: > pattern="_??.asc" seems not works. > <li>I would like to add one more loop to get list of folders (instead of > manually inserting directories into my_asc variable), but I haven't got > Idea > how I can do it? > <li>I do not know, why my way of creating vectors for mean, max, min and > standard deviation values is not working... > > > -- > View this message in context: > http://r.789695.n4.nabble.com/R-problem-with-my-loops-which-operate-on-raster-data-tp3497533p3497533.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsumner@gmail.com [[alternative HTML version deleted]]