TimeIntervalDataFrame {timetools} | R Documentation |
Class "TimeIntervalDataFrame"
Description
Class to hold time data that are NOT 'punctual'.
Usage
TimeIntervalDataFrame(start, end = NULL,
timezone = "UTC", data = NULL, period = NULL, sort=FALSE, ...)
as.TimeIntervalDataFrame(from, ...)
## S3 method for class 'TimeInstantDataFrame'
as.TimeIntervalDataFrame(from, period, ...)
RegularTimeIntervalDataFrame(from, to, by, period, timezone = "UTC", data = NULL)
## S4 method for signature 'TimeIntervalDataFrame'
x$name
## S4 replacement method for signature 'TimeIntervalDataFrame'
x$name <- value
## S3 method for class 'TimeIntervalDataFrame'
x[i, j, drop=FALSE]
## S3 replacement method for class 'TimeIntervalDataFrame'
x[i, j] <- value
## S4 method for signature 'TimeIntervalDataFrame'
x [[i, j, ...]]
## S3 replacement method for class 'TimeIntervalDataFrame'
x[[i, j]] <- value
## S3 method for class 'TimeIntervalDataFrame'
rbind(...)
## S3 method for class 'TimeIntervalDataFrame'
merge(x, y, by, all=TRUE, tz='UTC', sort=TRUE, ...)
## S3 method for class 'TimeIntervalDataFrame'
split(x, f, drop=FALSE, ...)
## S4 method for signature 'TimeIntervalDataFrame'
lapply(X, FUN, ...)
## S4 method for signature 'TimeIntervalDataFrame'
tapply(X, INDEX, FUN, ...,
min.coverage=1, weights.arg=NULL, merge.X=TRUE, split.X=FALSE,
keep.INDEX=TRUE, simplify=TRUE)
## S4 method for signature 'TimeIntervalDataFrame'
changeSupport(from, to,
min.coverage, FUN=NULL, weights.arg=NULL,
split.from=FALSE, merge.from=TRUE, ...)
## S4 method for signature 'TimeIntervalDataFrame'
continuous(x, ...)
## S4 replacement method for signature 'TimeIntervalDataFrame'
continuous(x) <- value
## S4 method for signature 'TimeIntervalDataFrame'
homogeneous(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
period(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
overlapping(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
regular(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
timezone(object)
## S4 replacement method for signature 'TimeIntervalDataFrame'
timezone(object) <- value
## S3 method for class 'TimeIntervalDataFrame'
start(x, ...)
## S3 method for class 'TimeIntervalDataFrame'
end(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
when(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
interval(x, ...)
## S4 method for signature 'TimeIntervalDataFrame'
dim(x)
## S4 method for signature 'TimeIntervalDataFrame'
length(x)
## S4 method for signature 'TimeIntervalDataFrame'
names(x)
## S4 replacement method for signature 'TimeIntervalDataFrame'
names(x) <- value
## S4 method for signature 'TimeIntervalDataFrame'
ncol(x)
## S4 method for signature 'TimeIntervalDataFrame'
nrow(x)
## S3 method for class 'TimeIntervalDataFrame'
row.names(x)
## S3 replacement method for class 'TimeIntervalDataFrame'
row.names(x) <- value
## S3 method for class 'TimeIntervalDataFrame'
print(x, tz=NULL, ...)
## S3 method for class 'TimeIntervalDataFrame'
summary(object, ...)
## S3 method for class 'TimeIntervalDataFrame'
head(x, tz, ...)
## S3 method for class 'TimeIntervalDataFrame'
tail(x, tz, ...)
## S4 method for signature 'TimeIntervalDataFrame'
show(object)
## S3 method for class 'TimeIntervalDataFrame'
plot(x, y=NULL, cursor=NULL,
type='p', lty=1:6, lwd=1, pch=1:25, col=NULL,
xlim=NULL, ylim=NULL, log='', main='', sub='', xlab='', ylab='',
ann=par('ann'), axes=TRUE, asp=NA, ...)
## S3 method for class 'TimeIntervalDataFrame'
points(x, y=NULL, cursor=NULL, type='p',
lty=1:6, lwd=1, pch=1:25, col=NULL, ...)
## S3 method for class 'TimeIntervalDataFrame'
lines(x, y=NULL, cursor=NULL, type='l',
lty=1:6, lwd=1, pch=1:25, col=NULL, ...)
## S3 method for class 'TimeIntervalDataFrame'
barplot(height, format='', ...)
Arguments
start |
POSIXct or character representing a time with a valid format
(see |
end |
POSIXct or character representing a time with a valid format
(see |
timezone |
character representing a valid timezone (see
|
data |
a data.frame with as much rows as the length
of ‘start’ and end, or with one row less than the
length of ‘start’ if ‘end’ is |
period |
|
from |
|
to |
|
by |
|
x |
TimeIntervalDataFrame object (to modify, to extract or to test) |
i |
indices specifying elements to extract or replace. (See
|
j |
indices specifying elements to extract or replace. (See
|
name |
A litteral character string or a name. (See
|
drop |
Used for compatibility with data.frame methods. |
value |
New value for the object designated (data.frame, names, row.names, etc.). |
y |
TimeIntervalDataFrame to merge with x |
all |
logical; see |
tz |
character representing a valid timezone (see
|
sort |
logical; if TRUE the resulting built/merged TimeIntervalDataFrame is ordered according to 'when' values. |
f |
a 'factor' in the sense that ‘as.factor(f)’ defines the
grouping, or a list of such factors in which case their
interaction is used for the grouping. See |
X |
|
FUN |
|
INDEX , min.coverage , weights.arg , merge.X , split.X , keep.INDEX , simplify , split.from , merge.from |
see |
object |
TimeIntervalDataFrame object (to modify, to extract or to test) |
type |
plotting argument, see |
lty |
plotting argument, see |
lwd |
plotting argument, see |
pch |
plotting argument, see |
col |
plotting argument, see |
xlim |
plotting argument, see |
ylim |
plotting argument, see |
log |
plotting argument, see |
main |
plotting argument, see |
sub |
plotting argument, see |
xlab |
plotting argument, see |
ylab |
plotting argument, see |
ann |
plotting argument, see |
axes |
plotting argument, see |
asp |
plotting argument, see |
cursor |
To convert TimeIntervalDataFrame to a TimeInstantDataFrame
before plotting (see |
height |
plotting argument, see |
format |
plotting argument, see |
... |
More arguments. |
Objects from the Class
Formally, the class consists of a data.frame
and, for each row, two POSIXct
that can
be summarize as time interval with the POSIXcti
class.
This allows to manipulate at once time data without any
restriction on time representation : data can occur at different time,
data can be discontinuous, data can be heterogeneous (not lasting
for a unique period), data can overlay each other, etc.
There are several methods to test/deal/ensure that
these properties are respected or not, see below.
The construction of the class allows to manipulate objects as if they were data.frame (see ‘Access to data’ and ‘Access to data properties’). Several functions are also available to access to time properties (see ‘Access to time properties’).
Methods are also available to facilitate the representations of instances of that class : see ‘graphic representation’ and ‘text representation’.
Finally, some specific methods allow to easily deal with agregation of data over time properties (day, hour, week, special or specific time intervals).
Slots
start
:Object of class
"POSIXct"
corresponding to the start of each row of thedata.frame
.end
:Object of class
"POSIXct"
corresponding to the end of each row of thedata.frame
.timezone
:Object of class
"character"
indicating the timezone of data both for representation and calculation.data
:Object of class
"data.frame"
data contained by the object.
TimeIntervalDataFrame constructors
Objects can be created by calls of the form
-
new("TimeIntervalDataFrame", ...)
... argument must be replaced by named arguments coresponding to slots of a TimeIntervalDataFrame (see below). See alsonew
. TimeIntervalDataFrame (start, end=NULL, timezone='UTC', data=NULL, ...)
Arguments of the function correspond to object slots. If bothstart
andend
are given, they must have the same length. They are used to define the intervals of the object. Ifdata
is also given, it must have a number of rows identical to the length ofstart
andend
.If only
start
is given, a continuous (seecontinuous
) TimeIntervalDataFrame is built. The first element ofstart
is the start of the first interval, the second element is the end of the first interval and the start of the second interval. The last element ofstart
is only the end of the last interval. This is whydata
, if given, must be one row shorter thanstart
.If period is given it must be a
POSIXctp
object (or a valid character) and ‘start’ and ‘end’ must have length equal to 1. In that case, a TimeIntervalDataFrame will be created with start date equal to start ‘floored’ by the unit of ‘period’, end date ‘ceiled’ by the unit of ‘period’ and with enough intervals of ‘period’ length to fit. If ‘data’ given, it must have a number of rows equal to the number of intervals calculated.-
RegularTimeIntervalDataFrame (from, to, by, period, timezone='UTC', data=NULL)
Wrapper to construct TimeIntervalDataFrame with specific properties (see details of each argument). -
as.TimeIntervalDataFrame (from, ...)
Converting object to TimeIntervalDataFrame.
Math
Every functions defined in the Ops group (see Ops
)
can be used width a TimeIntervalDataFrame and numeric :
tidf * 2
2 * tidf
2:10 == tidf
2^tidf
tidf^2
Accessing to and manipulating data
The TimeIntervalDataFrame class is defined to works like the data.frame class
with the difference that a time interval (POSIXcti
) is
attached to each rows of the data.frame. Thus to access and manipulate
data of a TimeIntervalDataFrame the following methods are defined :
'$', '$<-', '[', '[<-', '[[', '[[<-'. See Extract
for
details.
With ‘[’ operator, a selection by dates is also available. If ‘i’ and or ‘j’ are POSIXt or strings that can be converted to POSIXct (see below), they are considered as the minimal and maximal time limits : all datas between those are selected. A string that can be converted to a POSIXct is (in this case only) a string composed of 3 parts separated by white space : 'YYYY-MM-DD HH:MM:SS tz'. The second and third parts are options, thus accepted format are :
'YYYY-MM-DD'
'YYYY-MM-DD tz'
'YYYY-MM-DD HH:MM:SS'
'YYYY-MM-DD HH:MM:SS tz'
. If timezone is not given, it is assumed to be the same as the one of the object on which the selection is done.
Other methods have been defined to allow some operations on TimeIntervalDataFrame :
rbind and merge to join two (or more) TimeIntervalDataFrame (see
rbind
andmerge
),a TimeIntervalDataFrame can be splitted exactly the same way that a data.frame can (see
split
in the base package) and some more possibilities have been defined (seesplit
in the timetools package),a function can be applied over each column of a TimeIntervalDataFrame via the lapply function. If the function returns one value, the resulting value is a
TimeIntervalDataFrame
beginning at the first instant of the object and ending at the latest one ; else if the function returns as much values as the number of rows of the object, the TimeIntervalDataFrame given in argument is returned with the new calculated values ; on others cases, a non-TimeInterevalDataFrame object is returned.'tapply' can split a TimeIntervalDataFrame and then apply a function over each group (see
tapply
),'changeSupport' act like the 'tapply' function but with a different default behaviour (see
changeSupport
).
Because a TimeIntervalDataFrame works more or less like a data.frame,
the following methods work on a TimeIntervalDataFrame :
dim
,
length
,
names
,
names<-
,
ncol
,
nrow
,
row.names
,
row.names<-
.
Access/modify to time properties
A TimeIntervamDataFrame can be tested for a few time properties :
- continuous
see
continuous
;- homogeneous
see
homogeneous
;- period
see
period
;- overlapping
see
overlapping
;- regular
TRUE if all time intervals are equally spaced ;
- timezone
gives or sets the timezone of the TimeIntervalDataFrame ;
- start
returns a POSIXct object with the start time of each intervals ;
- end
returns a POSIXct object with the end time of each intervals ;
- when
returns a POSIXcti, i.e. the intervals of the object ;
- interval
returns a POSIXcti, i.e. the intervals of the object.
Graphic representation
To plot a TimeIntervalDataFrame
available functions are
plot
, lines
,
points
and barplot
.
These functions works more or less like their generic definition.
Text representation
To represent a TimeIntervalDataFrame
available functions are
print
,
summary
, head
,
tail
and show
.
See Also
TimeInstantDataFrame
, SubtimeDataFrame
,
POSIXcti
, POSIXctp
Examples
showClass("TimeIntervalDataFrame")