
Segue exemplo; ### spatio-temporal grid require(spacetime) nx <- 10; ny <- 10 gr <- GridTopology(c(0,0), c(1,1), c(nx,ny)) plot(sp <- SpatialPixels(SpatialPoints(coordinates(gr)))) (time = as.POSIXct("2013-01-01")+24*3600*(0:4)) ### data y <- rnorm(length(sp)*length(time), rep(1:length(time), each=length(sp))) ### spatio temporal (full) data frame stfdf <- STFDF(sp, time, data.frame(y, ID=1:length(y))) nrow(stfdf) dim(stfdf) ### 1) sampling ### 1.1) same spatial 'n' points each time ### in this case the result is a STDF so, ### but with irregular locations n <- 20 i1.1 <- sample(1:nrow(stfdf), n) dim(stfdf[i1.1,]) class(stfdf[i1.1,]) summary(stfdf[i1.1,]$y) tapply(stfdf[i1.1,]$y, rep(1:length(time), each=n), mean) ### 1.2) 'n' spatio temporal completely at random ### in this case the result is not a STDF, ### because now we have irregular spatio and ### also irregular time. So, the output is a STIDF n <- 30 i1.2 <- sort(sample(1:(length(sp)*length(time)), n)) ### identify index for space and time (splited) i1.2.s <- (i1.2-1)%%length(sp) + 1 i1.2.t <- (i1.2-1)%/%length(sp) + 1 ### get the spatial coordinates scoo <- do.call('rbind', lapply(unique(i1.2.t), function(t0) coordinates(stfdf[i1.2.s[i1.2.t==t0], t0]))) ### construct the STIDF object stidf <- STIDF(SpatialPoints(scoo), time[i1.2.t], stfdf@data[i1.2,]) Elias. On Wed, 2013-02-20 at 18:15 -0800, Samuel Carvalho wrote:
Boa noite caros membros da r-br Por gentileza, alguém saberia me dizer como amostrar um grid espacial em 3D? Tentei usar a função spsample do pacote sp, porém a mesma me parece que amostra apenas grid's em duas dimensoes. Obg, Samuel
==================================== Samuel P. C. Carvalho Mestre em Ciências Florestais [UFLA] Doutorando em Recursos Florestais [ESALQ/USP] ============================================= _______________________________________________ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível.