| match_types | R Documentation |
Useful after reading formats that do not store R classes (CSV, JSON, Excel): factors regain their levels (and ordering), dates and date-times are parsed, and integers/logicals are restored. Columns not present in the template are left unchanged.
match_types(x, template)
x |
A data frame. |
template |
A data frame with the desired column classes. |
Date-time strings ending in Z are read as UTC, strings with an explicit
offset (e.g. +02:00) are converted from that offset, and strings without
zone information are read as local times in the time zone of the template
column.
x with coerced columns.
f <- tempfile(fileext = ".csv")
write.csv(iris, f, row.names = FALSE)
x <- match_types(read.csv(f), iris)
identical(levels(x$Species), levels(iris$Species))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.