| c.timeline {datetime} | R Documentation |
Support for timepoint Classes
Description
These functions support classes timepoint, timeline, time, date, and datetime (and related functions). They are mostly S3 methods for base R generics.
Usage
## S3 method for class 'timeline'
c(..., recursive = FALSE)
## S3 method for class 'timeline'
x[..., drop = TRUE]
## S3 replacement method for class 'timepoint'
x[...] <- value
## S3 method for class 'timeline'
x[[..., drop = TRUE]]
## S3 method for class 'timepoint'
as.character(x, ...)
as.chartime(x, ...)
## S3 method for class 'numeric'
as.chartime(x, format, mark=TRUE,...)
## S3 method for class 'chartime'
as.numeric(x, format,...)
## S3 method for class 'timepoint'
print(x, ...)
## S3 method for class 'timeline'
rep(x, ...)
## S3 method for class 'timeline'
seq(from, to, by, length.out, along.with, ...)
Arguments
... |
arguments to |
recursive |
same meaning as for |
x |
object of class timepoint |
drop |
same meaning as for ‘[’ and ‘[[’ |
value |
value to be assigned, as for ‘[<-’ |
format |
input or output format describing character time (see |
mark |
boolean: mark times with dangling seconds using ‘+’ |
from |
as for |
to |
as for |
by |
as for |
length.out |
as for |
along.with |
as for |
Details
Normally you shouldn't need to worry about these functions. c and the ‘[’
variants exist just so that class information is not lost on invocation of the
generic. as.character.timepoint and print.timepoint just call format.
chartime variants are used internally by other functions. seq.timeline
requires from. If an interval cannot be calculated from supplied arguments,
by is set to 1 hour for time or 1 day for date or datetime.
Value
print |
an invisible object with same class as |
as.chartime |
generic: does not return |
as.chartime.numeric |
character (time) |
as.numeric.chartime |
numeric (seconds) |
as.character.timepoint |
character (time) |
others |
object with same class as |
Author(s)
Tim Bergsma
See Also
Examples
#as.data.frame
data.frame(
dt=as.datetime(seq(from=0,by=86500,length.out=3)),
d=as.date(seq(from=0,by=86400,length.out=3)),
t=as.time(c(60,120,180))
)
# dt d t
# 1 1970-01-01 00:00 1970-01-01 00:01
# 2 1970-01-02 00:01+ 1970-01-02 00:02
# 3 1970-01-03 00:03+ 1970-01-03 00:03
#combine
c(as.time(0),as.time(60))
# 00:00 00:01
c(as.date(0),as.date(86400))
# 1970-01-01 1970-01-02
c(as.datetime(0),as.datetime(86500))
# 1970-01-01T00:00 1970-01-02T00:01+
#subset
as.time(c('08:00','09:00'))[2]
# 09:00
as.date(c('2008-01-01','2008-01-04'))[2]
# 2008-01-04
as.datetime(c('2008-01-01T12:00','2008-01-04T12:30'))[2]
# 2008-01-04 12:30
#element selection
as.time(c('08:00','09:00'))[[2]]
# 09:00
as.date(c('2008-01-01','2008-01-04'))[[2]]
# 2008-01-04
as.datetime(c('2008-01-01T12:00','2008-01-04T12:30'))[[2]]
# 2008-01-04 12:30
#assignment
a <- as.time(seq(60,300, by=60))
a#00:01 00:02 00:03 00:04 00:05
a[5] <- 60
a#00:01 00:02 00:03 00:04 00:01
a[3] <- NA
a#00:01 00:02 <NA> 00:04 00:01
#identity
as.time(as.time(0))
# 00:00
as.date(as.date(0))
# 1970-01-01
as.datetime(as.datetime(0))
# 1970-01-01T00:00
#repetition
rep(as.time(86340),2)
# 23:59 23:59
#sequence
seq(from=as.time('00:00'),length.out=3)
seq(from=as.time('00:00'),by=as.time('00:05'),length.out=3)
seq(from=as.time('00:00'),by=as.time('00:05'),along.with=integer(3))
seq(from=as.time('00:00'),to=as.time('06:00'))
seq(from=as.time('00:00'),to=as.time('06:00'),by=as.time('02:00'))
seq(from=as.time('00:00'),to=as.time('06:00'),length.out=4)