[R-sig-Geo] STFDF with n variables

Edzer Pebesma edzer.pebesma at uni-muenster.de
Sun Dec 16 20:53:58 CET 2012



On 12/16/2012 08:28 PM, Piero Campalani wrote:
> Oh, right,
> I actually can see that things work fine even with no "id" attribute in the
> data.frame.
> 
> I started it all by following an example of Roger with NDVI images of
> Gambia, where the initial wide-format dataframe was `reshape`d to
> long-format to eventually create a STFDF: the ids were used there.
> Afaics, one can keep trace of the spatial location of each row with the IDs
> when going from a time-wide format to a long one, otherwise the spatial
> dimension gets flattened with no chance of reverting to time-wide format.

Piero, there is a chance: if the layout is complete (full: STFDF) you
can recreate space and time ID from row order,

> ((1:prod(dim(stMeuse)[1:2])-1) %% dim(stMeuse)[1] + 1)
 [1]  1  2  3  4  5  6  7  8  9 10  1  2  3  4  5  6  7  8  9 10
> ((1:prod(dim(stMeuse)[1:2])-1) %/% dim(stMeuse)[1] + 1)
 [1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2

For an irregular layout, STIDF, the IDs are kept in the index slot.

Indeed, you need to know that space cycles fastest, and so it is easy to
make mistakes.

> Thought they were used by STFDF to link the locations in the spatial object
> and the values in the data.frame.
> 
> Thanks again Edzer.
> Cheers,
> Piero
> 
> 
> On 16 December 2012 19:53, Edzer Pebesma <edzer.pebesma at uni-muenster.de>wrote:
> 
>> Piero,
>>
>> in your case id is simply an attribute, so it can have any value, as you
>> can see from:
>>
>> stplot(stMeuse[,,1:4], mode = 'ts')
>>
>> what is the special purpose of your IDs, what should they identify?
>>
>> On 12/16/2012 07:42 PM, Piero Campalani wrote:
>>> Thank you Edzer,
>>> comments inline
>>>
>>> On 16 December 2012 19:19, Edzer Pebesma <edzer.pebesma at uni-muenster.de
>>> wrote:
>>>>
>>>> Yes, that works:
>>>>
>>>>> class(stMeuse)
>>>> [1] "STFDF"
>>>> attr(,"package")
>>>> [1] "spacetime"
>>>>> dim(stMeuse)
>>>>     space      time variables
>>>>        10         2         4
>>>>
>>>
>>> I could see that a STFDF object was created, but I still have some
>> concern
>>> with regard to the "id" which need to be attached to the data.frame .
>>>
>>> With regards to my example, I tried as well with reverse-order IDs:
>>>> ds <- cbind(ds, time=sort(rep(dts,10)), id=nrow(ds):1)
>>> ...or with duplicated IDs like:
>>>> ds <- cbind(ds, time=sort(rep(dts,10)), id=rep(1:10,2))
>>> and the final stMeuse object still seemed the same by looking at
>>> stplot(stMeuse).
>>> I guess they are not bound to the locations of the spatial object (points
>>> in `meuse` in this case).
>>>
>>>
>>>> (also note that with the CRAN version of spacetime, you'd need to load
>>>
>>> package zoo first in order to run your script)
>>>>
>>>
>>> Got it, thanks ;)
>>>
>>> Piero
>>>
>>
>> --
>> Edzer Pebesma
>> Institute for Geoinformatics (ifgi), University of Münster
>> Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
>> 8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
>> http://www.52north.org/geostatistics      e.pebesma at wwu.de
>>
>>
> 
> 	[[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
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list