retype {hablar} | R Documentation |
Return simple data types
Description
retype
transforms all elements into simple classes. The simple classes
are date, numeric and character. By transforming all elements to these
classes no information is lost, while simplifying the object. See details below for
more information or type vignette("retype")
in the console.
Usage
retype(.x, ...)
## Default S3 method:
retype(.x, ...)
## S3 method for class 'logical'
retype(.x, ...)
## S3 method for class 'integer'
retype(.x, ...)
## S3 method for class 'Date'
retype(.x, ...)
## S3 method for class 'POSIXct'
retype(.x, ...)
## S3 method for class 'numeric'
retype(.x, ...)
## S3 method for class 'list'
retype(.x, ...)
## S3 method for class 'data.frame'
retype(.x, ...)
Arguments
.x |
vector or data.frame |
... |
column names to be evaluated. Only if .x is a data frame. |
Details
Each vector past to retype
is reclassified into the highest position in
a simplification hierarchy without loosing any information. This means that:
Factors are converted to characters.
However, character vectors (or vectors changed to character initially)
are checked to see if they could be a numeric vector without error.
If so, it is transformed into a numeric vector which is higher in the hierarchy.
Vectors of class logical, integer are changed to numerical.
Dates and date time (POSIXct) goes through the same procedure.
Lists and complex vectors are left unchanged because the are neither simple nor complicated.
Value
For vectors: simple class of .x.
For data.frame: a tbl data frame with simple classes.
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
See Also
s
, rationalize
#' vignette("retype")
, vignette("s")
, vignette("hablar")
Examples
# Dates
dte <- as.Date(c("2018-01-01", "2016-03-21", "1970-01-05"))
retype(dte)
retype(dte)
# Factors
fct <- as.factor(c("good", "bad", "average"))
retype(dte)
# Character that only contains numeric elements
num_chr <- c("3","4.0", "3,5")
retype(num_chr)
# Logical
lgl <- c(TRUE, FALSE, TRUE)
retype(lgl)
# Data frame with all the above vectors
df <- data.frame(dte = dte,
fct = fct,
num_chr = num_chr,
lgl = lgl,
stringsAsFactos = FALSE)
df
retype(df)