tframe: Extract or Set a tframe

Description Usage Arguments Details Value See Also Examples

View source: R/tframe.R

Description

Extract or set the tframe of an object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    as.tframe(...)
    as.tframed(x)

    tframe(x)
    ## Default S3 method:
tframe(x)
    ## S3 method for class 'ts'
tframe(x)

    tframe(x) <- value
    tfSet(value, x) 
    ## Default S3 method:
tfSet(value, x) 
    ## S3 method for class 'list'
tfSet(value, x) 
    ## S3 method for class 'tstframe'
tfSet(value, x) 

    tframed(x, tf=NULL, names = NULL, ...)
    ## Default S3 method:
tframed(x, tf = NULL, names = NULL, start=NULL, end=NULL, ...)

    is.tframe(x)
    is.tframed(x)

Arguments

x

an object (to which a tframe is assigned in assignment methods).

value

a tframe.

tf

a tframe object or a tframed object from which a tframe is taken.

start

provides simple way to specify a tframed time series similar to a ts object.

end

provides simple way to specify a tframed time series similar to a ts object.

names

optional vector of strings to specify new series names.

...

arguments passed to default to construct a tframe (rather than extract one from x.) frequency might often be used if start or end are specified.

Details

The usage tframe(x) returns the tframe of a tframed object. The assignment tframe(x)<-, tfSet, and tframed set the tframe of an object. as.tframe(...) constucts a tframe from .... is.tframe and is.tframed return logicals if the argument is a tframe or tframed object respectively. as.tframed guarantees x has a tframe by assigning a default if x does not already have a tframe.

The object of these functions is to be able to write code with tframe(y) <- tframe(x), to assign the tframe attributes of x to y, without needing to handle details of the time representation and without concern for the number of series in x and y, which need not be the same. A check is made to ensure the number of periods in the data correspond with the number implied by the tframe.

There is an attempt to use the same time representation for y as x has (e.g. ts, zoo, its), but this cannot be guaranteed because y may not be representable using the x represnetation. For example, x might be an "mts" constructed with ts() whereas y is a list with some data structures. In this case, a "pure tframe" approach is used.

The pure tframe approach sets a "tframe" attribute in object. This attribute has a class which indicates the time framing which is used. The the time frame information is often secondary, in the sense that it does not describe the object structure, but only provides some additional information which is useful for doing time based operations on the data, plotting, and printing the object. By putting this in an attribute, the objects class can be used for indicating other information about the structure of the object. For these pure tframe objects the default tframe and tframe<- will often be adequate. The generic/method approach allows for special case (like TSdata where the tframe information is not an attribute of the object, but rather an attribute of the data matrices which are elements of the object).

The generic/method approach also allows for (faking) tframe assignment and extraction with classes like zoo, its, ts, and others which may appear, that try to make the time description part of the object class. (Not a "tframe" approach.) The problem is to extract real tframes and also fake these other classes and old style tsp objects so they look like tfamed objects. Another approach would be to mutilate these objects and force them really be tframed objects (to have a tframe attribute), but that risks conflicting with other (non tframe) code which used the objects. This faking is accomplished by specific methods of the classes.

The tframed constructor is simply a shortcut for assigning the tframe (tframe(x) <- tf) and series names (seriesNames(x) <- names) to an object, but never assigns NULL values, so the result is guaranteed to be a tframed object. It is like ts but enables the tframe library's methods for handling time. If the tf argument is a tframed object rather than a tframe, then the tframe is extracted and used. If the names argument is not mode "character" of appropriate length, then seriesNames(names) is used. These make it simple to assign the time frame and names of one object to another by z <- tframed(x, tf=y, names=y).

is.tframed returns TRUE if a tframe() can extract a tframe from the object. This is true for many objects which are not truly tframed (like ts objects), since tframe() tries fairly hard to build a tframe for the object.

Value

Depends.

See Also

tfstart, tfend, tffrequency, Tobs, tftime, tfL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    z <- tframe(ts(rnorm(100), start=c(1982,1), frequency=12))
    z
    is.tframe(z)
    zz <- tframed(matrix(rnorm(200), 100,2), tf=z)
    is.tframed(zz)
    zzz <- tframed(matrix(rnorm(200), 100,2), tf=zz)
    is.tframed(zzz)
    tframe(zzz)
    
    as.tframe(start=c(1992,1), end=c(1996,3), frequency=4)
    Tobs(as.tframe(start=c(1992,1), end=c(1996,3), frequency=4))
    end(as.tframe(start=c(1992,1), end=c(1996,3), frequency=4))

    z <- tframed(rnorm(100), start=c(1982,1), frequency=12)

tframe documentation built on Sept. 23, 2019, 3:01 a.m.

Related to tframe in tframe...