[R] Why stacking rasters return NAs?

PIKAL Petr petr.pikal at precheza.cz
Tue Mar 19 12:15:22 CET 2013


Hi

> -----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:56 AM
> To: r-help at r-project.org
> Subject: Re: [R] Why stacking rasters return NAs?
> 
> stacking the rasters will make them as multi layers as they have the
> same dimension exten ... so as one layer.

You are rather cryptic in what you want to do. What is raster, what is dimension exten? Wikipedia gives 11 possibilities for raster and two guys with such name.

>From what you describe without any real example data it seems to me that you have some matrices let say 10x10 and you want to put them together so as to calculate let say mean for defined cell (let say top left for each matrix).

You can use either array or list

mat1<-matrix(1:4, 2,2)
mat2<-matrix(1:4, 2,2)

aaa<-array(c(mat1, mat2), dim=c(2,2,2))
mean(aaa[,,1])
[1] 2.5
mean(aaa[1,,])
[1] 2
mean(aaa[1,1,])
[1] 1
sum(aaa[1,1,])
[1] 2
sum(aaa[1,2,])
6

Anyway, to spare anybody's time I recommend you to follow posting guide and provide some reproducible example

Regards
Petr

> 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.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list