[R-sig-Geo] create a TS with multiple raster files

Oscar Perpiñán Lamigueiro oscar.perpinan at gmail.com
Wed Apr 18 11:55:53 CEST 2012


Jacob van Etten <jacobvanetten at yahoo.com> writes:

> Dear Nora,
>
> The best thing would be to read the vignette of the raster package first.
>
> A combination of raster layers is not a data frame, but a stack.
>
> This is how you make one, following your example:
>
>
> st <- get(list.files(pattern='*.rst')[1])
>
> for (f in list.files(pattern='*.rst')[-1]) {st <- stack(st, get(f))}
>
Another approach is to pass the result of list.files directly to stack
(if I am not wrong you do not want the first file to be included, that's
why I use [-1]):

library(raster)

rst <- list.files(pattern='*.rst')
s <- stack(rst[-1])

If this stack is a space-time data you can use the setZ function. If idx
is the time index of the data:

s <- setZ(s, idx)

Best,

Oscar.
>
>
> ________________________________
>  From: Nora Schmid <noerchen306 at gmail.com>
> To: r-sig-geo at r-project.org 
> Sent: Tuesday, 17 April 2012, 9:25
> Subject: [R-sig-Geo] create a TS with multiple raster files
>
> Hello,
>
> Im new in R and dont have lots of experiences with programming...
> Im trying to create a time series:
> I read my raster data with the following:
>
> for (f in list.files(pattern='*.rst')){assign(f, raster(f))}
>
> How can I create afterwards a time series with the files I loaded? How
> can I assign all files to one data frame? Whats the best way to create
> from multiple raster files on time series?
>
> Thanks a lot in advance,
>
> yours
>
> Nora
>
>   [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-------------- next part --------------

-- 
Oscar Perpi??n Lamigueiro
Dpto. Ingenier?a El?ctrica
EUITI-UPM
URL: http://procomun.wordpress.com
Twitter: @oscarperpinan


More information about the R-sig-Geo mailing list