| as.Date.haven_labelled_defined | R Documentation |
Coerces a haven_labelled_defined vector whose underlying type is
Date into a base R Date vector.
This method preserves the underlying date values and, by default, also retains any semantic metadata attached to the variable.
## S3 method for class 'haven_labelled_defined'
as.Date(x, strip_attributes = FALSE, ...)
x |
A vector created with |
strip_attributes |
Logical; should the semantic metadata attributes
(label, unit, definition, namespace) be removed from the returned
vector? 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.Date() also works, as it dispatches to this method via
S3. However, using as.Date() on defined vectors is considered safe
because this method ensures metadata is handled predictably.
A Date vector, optionally carrying semantic metadata.
as.POSIXct(),
as_numeric(), as_character(), as_logical(),
defined()
d <- defined(Sys.Date() + 0:2, label = "Observation date")
# Recommended usage
as.Date(d)
# Stripping metadata
as.Date(d, strip_attributes = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.