I have several rasters that I want to do some calculations ,basically calculating the moving average. dir2 <- list.files("D:\\2010+2011", "*.bin", full.names = TRUE) saf=stack(dir2) movi <- overlay(stack(saf),fun=function(x) movingFun(x, fun=mean, n=3, na.rm=TRUE)) Error in .overlayList(x, fun = fun, filename = filename, ...) : cannot use this formula, probably because it is not vectorized I then checked the data but found that all values were returnd as NA and this may explain why i am getting the error. saf class : RasterStack dimensions : 720, 1440, 1036800, 601 (nrow, ncol, ncell, nlayers) resolution : 0.25, 0.25 (x, y) extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs names : Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, , ... min values : NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ... max values : NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, ... I wonder why this is happening, I checked the files separably(summary) and everything was right!as you can see bellow: ol_025_H14_2011092000_1_wgs84 Vol_025_H14_2011092100_1_wgs84 Vol_025_H14_2011092200_1_wgs84 Vol_025_H14_2011092300_1_wgs84 Vol_025_H14_2011092400_1_wgs84 Min. 0.00000 0.0000000 0.0000000 0.0000000 0.0000000 1st Qu. 0.31883 0.3163167 0.3146436 0.3113111 0.3064551 Median 9999.00000 9999.0000000 9999.0000000 9999.0000000 9999.0000000 3rd Qu. 9999.00000 9999.0000000 9999.0000000 9999.0000000 9999.0000000 Max. 9999.00000 9999.0000000 9999.0000000 9999.0000000 9999.0000000 NA's 0.00000 0.0000000 0.0000000 0.00000 I am gratful to anyhelp -- View this message in context: http://r.789695.n4.nabble.com/Why-stacking-rasters-return-NAs-tp4661706.html Sent from the R help mailing list archive at Nabble.com.
Hi You use several functions which are not base without mentioning their source, therefore you probably won't get much help. I wonder that you do not get error with stack. AFAIK you will get a character vector in dir2. stack a character vector results in error> stack(letters)Error in rep.int(names(x), lapply(x, length)) : invalid 'times' value>Normally stack works on lists or data frames> testteorie kal1 kal2 kal3 1 2 2.04 1.80 1.851 2 4 4.07 3.50 3.753 3 6 5.86 5.23 5.663 4 8 7.87 7.09 7.598 5 10 10.01 8.87 9.428 6 12 NA 10.61 11.308> stack(test)values ind 1 2.000 teorie 2 4.000 teorie 3 6.000 teorie 4 8.000 teorie 5 10.000 teorie 6 12.000 teorie 7 .... So you either have some other stack function or I am completly out of the topic. Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Jonsson > Sent: Monday, March 18, 2013 6:32 PM > To: r-help at r-project.org > Subject: [R] Why stacking rasters return NAs? > > I have several rasters that I want to do some calculations ,basically > calculating the moving average. > > dir2 <- list.files("D:\\2010+2011", "*.bin", full.names > TRUE) > saf=stack(dir2) > movi <- overlay(stack(saf),fun=function(x) movingFun(x, > fun=mean, n=3, na.rm=TRUE)) > Error in .overlayList(x, fun = fun, filename = filename, > ...) : > cannot use this formula, probably because it is not vectorized > I then checked the data but found that all values were returnd as NA > and this may explain why i am getting the error. > > saf > class : RasterStack > dimensions : 720, 1440, 1036800, 601 (nrow, ncol, ncell, > nlayers) > resolution : 0.25, 0.25 (x, y) > extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax) > coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 > +no_defs > names : Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, > Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, Vol_025_H//00_1_wgs84, > Vol_025_H//00_1_wgs84, , ... > min values : NA, NA, > NA, NA, NA, > NA, > NA, NA, NA, > NA, > NA, NA, NA, > NA, > NA, ... > max values : NA, NA, > NA, NA, NA, > NA, > NA, NA, NA, > NA, > NA, NA, NA, > NA, > NA, ... > > > I wonder why this is happening, I checked the files separably(summary) > and everything was right!as you can see bellow: > > ol_025_H14_2011092000_1_wgs84 > Vol_025_H14_2011092100_1_wgs84 > Vol_025_H14_2011092200_1_wgs84 Vol_025_H14_2011092300_1_wgs84 > Vol_025_H14_2011092400_1_wgs84 > Min. 0.00000 > 0.0000000 > 0.0000000 0.0000000 0.0000000 > 1st Qu. 0.31883 > 0.3163167 > 0.3146436 0.3113111 0.3064551 > Median 9999.00000 > 9999.0000000 > 9999.0000000 9999.0000000 > 9999.0000000 > 3rd Qu. 9999.00000 > 9999.0000000 > 9999.0000000 9999.0000000 > 9999.0000000 > Max. 9999.00000 > 9999.0000000 > 9999.0000000 9999.0000000 > 9999.0000000 > NA's 0.00000 > 0.0000000 > 0.0000000 0.00000 > > I am gratful to anyhelp > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Why- > stacking-rasters-return-NAs-tp4661706.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thanks. Could you please tell me how to stack all those files properly? -- View this message in context: http://r.789695.n4.nabble.com/Why-stacking-rasters-return-NAs-tp4661706p4661784.html Sent from the R help mailing list archive at Nabble.com.
Hi Please describe what do you mean by stacking files? Stack takes each numeric column of data frame and transform it to two column data frame with one column being numeric value and the other column an indicator based on column name. see head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa stack(head(iris)) Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Jonsson > Sent: Tuesday, March 19, 2013 11:36 AM > To: r-help at r-project.org > Subject: Re: [R] Why stacking rasters return NAs? > > Thanks. Could you please tell me how to stack all those files properly? > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Why- > stacking-rasters-return-NAs-tp4661706p4661784.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
stacking the rasters will make them as multi layers as they have the same dimension exten ... so as one layer. so we can do calculation with them. -- View this message in context: http://r.789695.n4.nabble.com/Why-stacking-rasters-return-NAs-tp4661706p4661787.html Sent from the R help mailing list archive at Nabble.com.