retype | R Documentation |
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.
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, ...)
.x |
vector or data.frame |
... |
column names to be evaluated. Only if .x is a data frame. |
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.
For vectors: simple class of .x.
For data.frame: a tbl data frame with simple classes.
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
s
, rationalize
#' vignette("retype")
, vignette("s")
, vignette("hablar")
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.