| as.tind | R Documentation |
tind Classas.tind method allows for conversion of numeric and character vectors
as well as objects of Date, POSIXct, and POSIXlt
classes to tind objects to tind.
as.tind method for tind class allows to change the type
of index of an object of tind class.
Convenience functions as.year, as.quarter, as.month,
as.week, as.date, as.date_time, as.time allow
to quickly convert argument to the indicated type.
as.tind(x, ...)
## S3 method for class 'numeric'
as.tind(x, type = NULL, tz = NULL, ...)
## S3 method for class 'character'
as.tind(
x,
type = NULL,
format = NULL,
order = NULL,
locale = NULL,
tz = NULL,
...
)
## S3 method for class 'Date'
as.tind(x, ...)
## S3 method for class 'POSIXct'
as.tind(x, tz = NULL, digits = 0L, ...)
## S3 method for class 'POSIXlt'
as.tind(x, tz = NULL, digits = 0L, ...)
## S3 method for class 'data.frame'
as.tind(x, ...)
## S3 method for class 'tind'
as.tind(x, type = NULL, tz = NULL, ...)
as.year(x, ...)
as.quarter(x, ...)
as.month(x, ...)
as.week(x, ...)
as.date(x, ...)
as.date_time(x, tz = NULL, ...)
as.time(x, ...)
x |
an R object (e.g., a numeric vector, a character vector, a |
... |
further arguments passed to or from other methods. |
type |
a character determining time index type or |
tz |
(optional) a character value determining the time zone (the default
|
format |
a character determining input format(s) as in |
order |
a character determining order(s) of time index components
in the input as in |
locale |
(optional) a character value determining locale or |
digits |
an integer value (0–6) determining the number of decimal places for seconds to be preserved during conversion (0 by default). |
Numeric vectors
The following numeric representations are automatically recognised
(between year 1800 and 2199): YYYY (years), YYYYQ (quarters),
YYYYMM (months), and YYYYMMDD (dates). Conversion from
numeric vectors to other index types requires type specification via type
argument.
Date-time indices are represented as number of seconds since the Epoch (1970-01-01 00:00 UTC). Time of day is represented as the number of seconds since midnight.
Character vectors
as.tind automatically recognises many different formats. If automatic
recognition fails, type argument could help identify the format.
For less standard formats / representations, one can use either format
argument (which is forwarded to strptind) or order
argument (which is forwarded to parse_t).
Data frames
If a data frame has one column, it is converted using appropriate method
depending on the column type. In case there are two or more columns, they are
pasted and the resulting character vector is parsed. As this may not be
computationally efficient, other ways of constructing tind should be
considered, for example, use of tind constructor.
Date and POSIXt classes
Conversion of Date objects returns time index of type "d" (date).
POSIXct and POSIXlt classes are converted to index of type "t"
(date-time). If time zone attribute is not set for the argument, system time zone
is assumed.
Other classes representing time indices
For conversions between tind class and other classes (from packages
other than base), see tind-other.
An object of tind class of length equal to the length of the argument.
For data frame version the length of the result is equal to the number of rows
in the data frame.
tind constructor,
strptind function for format specifications,
parse_t function for order specifications,
tind-coercion for conversions from tind,
and tind-other for conversions between tind class and
other classes (from packages other than base).
## numeric and character arguments
# years
as.tind(1999)
as.tind("1999")
# quarters
as.tind(20043)
as.tind("20043")
# months
as.tind(200109)
as.tind("2001-09")
as.tind("200109")
# need proper locale to recognise English month names
as.tind("Sep 2001", locale = "C")
# weeks (ISO 8601)
# numeric YYYYWW representation is not automatically recognised, need type
as.tind(200936, "w")
as.tind("2009-W36")
# dates
as.tind(20200726)
as.tind("2020-07-26")
# need proper locale to recognise English month names
as.tind("Jul 26, 2020", locale = "C")
as.tind("07/26/20")
# date-time
as.tind("2000-08-16 08:17:38")
# time
as.tind("08:17:38")
as.tind(08 * 3600 + 17 * 60 + 38, type = "h")
## conversion from Date and POSIXct
as.tind(Sys.Date())
as.tind(Sys.time())
## as.year, ..., as.time
# today
(x <- today())
as.year(x)
as.quarter(x)
as.month(x)
as.week(x)
# midnight
as.date_time(x)
# current time
(x <- now())
as.year(x)
as.quarter(x)
as.month(x)
as.week(x)
as.date(x)
as.time(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.