| as.POSIXct.haven_labelled_defined | R Documentation |
Coerces a haven_labelled_defined vector whose underlying type is
POSIXct into a base R POSIXct time vector.
This method preserves both the timestamp values and the original time zone. By default, semantic metadata is also retained.
## S3 method for class 'haven_labelled_defined'
as.POSIXct(x, tz = "", strip_attributes = TRUE, ...)
x |
A vector created with |
tz |
a character string. The time zone specification to be used for
the conversion, if one is required. System-specific timezones
(see |
strip_attributes |
Logical; should semantic metadata attributes
(label, unit, definition, namespace) be removed? Defaults to
|
... |
Additional arguments passed to |
Use strip_attributes = TRUE when flattening or preparing data for
external pipelines, but keep the default when working with defined
vectors directly.
Base R's as.POSIXct() also works, as it dispatches to this method via
S3. Using this method directly is preferred when metadata preservation
matters.
A POSIXct vector with timestamp values preserved.
as.Date(),
as_numeric(), as_character(), as_logical(),
defined()
p <- defined(
as.POSIXct("2024-01-01 12:00:00", tz = "UTC"),
label = "Timestamp"
)
# Recommended usage
as.POSIXct(p)
# Explicit attribute stripping
as.POSIXct(p, strip_attributes = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.