[R] How numerical data is stored inside ts time series objects
William Dunlap
wdunlap at tibco.com
Wed Apr 22 04:16:10 CEST 2015
> Interesting that a 2D matrix of size Nx1 is treated as a different
> animal from a length N vector.
I think we can call this a bug in stl().
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Tue, Apr 21, 2015 at 6:39 PM, Paul <Paul.Domaskis at gmail.com> wrote:
> William Dunlap <wdunlap <at> tibco.com> writes:
> > Use the str() function to see the internal structure of most
> > objects. In your case it would show something like:
> >
> > > Data <- data.frame(theData=round(sin(1:38),1))
> > > x <- ts(Data[[1]], frequency=12) # or Data[,1]
> > > y <- ts(Data, frequency=12)
> > > str(x)
> > Time-Series [1:38] from 1 to 4.08: 0.8 0.9 0.1 -0.8 -1 -0.3 0.7 1 0.4 -
> 0.5
> > ...
> > > str(y)
> > ts [1:38, 1] 0.8 0.9 0.1 -0.8 -1 -0.3 0.7 1 0.4 -0.5 ...
> > - attr(*, "dimnames")=List of 2
> > ..$ : NULL
> > ..$ : chr "theData"
> > - attr(*, "tsp")= num [1:3] 1 4.08 12
> >
> > 'x' contains a vector of data and 'y' contains a 1-column matrix of
> > data. stl(x,"per") and stl(y, "per") give similar results as you
> > got.
> >
> > Evidently, stl() does not know that 1-column matrices can be treated
> > much the same as vectors and gives an error message. Thus you must
> > extract the one column into a vector: stl(y[,1], "per").
>
> Thanks, William.
>
> Interesting that a 2D matrix of size Nx1 is treated as a different
> animal from a length N vector. It's a departure from math convention,
> and from what I'm accustomed to in Matlab. that R's vector seems
> more akin to a list, where the notion of orientation doesn't apply.
>
> I rummaged around the help files for str, summary, dput, args. This
> seems like a more complicated language than Matlab, VBA, or even C++'s
> STL of old (which was pretty thoroughly documented). A function like
> str() returns an object description, and I'm guessing the conventions
> with which the object is described depends a lot on the person who
> wrote the handling code for the class. The description for the
> variable y seems particularly elaborate.
>
> Would I be right in assuming that the notation is ad-hoc and not
> documented? For example, the two invocations str(x) and str(y) show a
> Time-Series and a ts. And there are many lines of output for str(y)
> that is heavy in punctuation.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list