[R] How to extend a slot of a class?

Igor Sosa Mayor joseleopoldo1792 at gmail.com
Fri Mar 16 14:00:23 CET 2012


i think if you do:

coord$time<-YOURTIMEVECTOR

should work and the new vector is put correctly in the data slot.

Maybe also

coord at data$time<-YOURTIMEVECTOR

On Wed, Mar 14, 2012 at 01:39:20PM +0100, Marco Smolla wrote:
> Hej hej,

> is there a way to extend the SpatialPointsDataFrame data slot?This is the structure of an object of it:> str(coord)
> Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots
>   ..@ data       :'data.frame':	214 obs. of  2 variables:
>   .. ..$ location.long: num [1:214] -79.8 -79.8 -79.8 -79.8 -79.8 ...
>   .. ..$ location.lat : num [1:214] 9.16 9.16 9.16 9.16 9.16 ...
>   ..@ coords.nrs : num(0) 
>   ..@ coords     : num [1:214, 1:2] -79.8 -79.8 -79.8 -79.8 -79.8 ...
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : NULL
>   .. .. ..$ : chr [1:2] "location.long" "location.lat"
>   ..@ bbox       : num [1:2, 1:2] -79.84 9.16 -79.84 9.17
>   .. ..- attr(*, "dimnames")=List of 2
>   .. .. ..$ : chr [1:2] "location.long" "location.lat"
>   .. .. ..$ : chr [1:2] "min" "max"
>   ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots
>   .. .. ..@ projargs: chr NA

> data is a data.frame including the information of long and lat location. I would like to have there a third information: time (but as POSIXct). Is there an elegant way to do this?

> Best,
> marco
> 	[[alternative HTML version deleted]]

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

-- 
:: Igor Sosa Mayor   :: joseleopoldo1792 at gmail.com ::
:: GnuPG: 0x1C1E2890 :: http://www.gnupg.org/      ::



More information about the R-help mailing list