[R] Confused about behavior of an S4 object containing a ts object
Lyman, Mark
Mark.Lyman at atk.com
Thu Dec 18 21:01:58 CET 2008
I am trying to define an S4 class that contains a ts class object, a
simple
example is shown in the code below. However, when I try to create a new
object
of this class the tsp part is ignored, see below. Am I doing something
wrong,
or is this just a peril of mixing S3 and S4 objects?
> setClass("tsExtended", representation = representation(description
= "character"), contains = "ts")
[1] "tsExtended"
> new("tsExtended", ts(1:10, frequency = 2), description = "My Time
Series")
Object of class "tsExtended"
Time Series:
Start = 1
End = 10
Frequency = 1
[1] 1 2 3 4 5 6 7 8 9 10
Slot "description":
[1] "My Time Series"
> # This however seems to work
> tmp <- new("tsExtended", 1:10, description = "My Time Series")
> tsp(tmp) <- c(1, 5.5, 2)
> tmp
Object of class "tsExtended"
Time Series:
Start = c(1, 1)
End = c(5, 2)
Frequency = 2
[1] 1 2 3 4 5 6 7 8 9 10
Slot "description":
[1] "My Time Series"
Mark Lyman, Statistician
Engineering Systems & Integration, ATK
More information about the R-help
mailing list