Description Usage Arguments Details Value Functions See Also Examples
View source: R/convert_to_date.R
Convert many date and datetime formats as may be received from Microsoft Excel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | convert_to_date(
x,
...,
character_fun = lubridate::ymd,
string_conversion_failure = c("error", "warning")
)
convert_to_datetime(
x,
...,
tz = "UTC",
character_fun = lubridate::ymd_hms,
string_conversion_failure = c("error", "warning")
)
|
x |
The object to convert |
... |
Passed to further methods. Eventually may be passed to 'excel_numeric_to_date()', 'base::as.POXIXct()', or 'base::as.Date()'. |
character_fun |
A function to convert non-numeric-looking, non-NA values in 'x' to POSIXct objects. |
string_conversion_failure |
If a character value fails to parse into the desired class and instead returns 'NA', should the function return the result with a warning or throw an error? |
tz |
The timezone for POSIXct output, unless an object is POSIXt already. Ignored for Date output. |
Character conversion checks if it matches something that looks like a Microsoft Excel numeric date, converts those to numeric, and then runs convert_to_datetime_helper() on those numbers. Then, character to Date or POSIXct conversion occurs via 'character_fun(x, ...)' or 'character_fun(x, tz=tz, ...)', respectively.
POSIXct objects for 'convert_to_datetime()' or Date objects for 'convert_to_date()'.
convert_to_datetime
: Convert to a date-time (POSIXct)
Other Date-time cleaning:
excel_numeric_to_date()
1 2 3 4 5 6 7 8 9 | convert_to_date("2009-07-06")
convert_to_date(40000)
convert_to_date("40000.1")
# Mixed date source data can be provided.
convert_to_date(c("2020-02-29", "40000.1"))
convert_to_datetime(
c("2009-07-06", "40000.1", "40000", NA),
character_fun=lubridate::ymd_h, truncated=1, tz="UTC"
)
|
sh: 1: cannot create /dev/null: Permission denied
sh: 1: cannot create /dev/null: Permission denied
Attaching package: ‘janitor’
The following objects are masked from ‘package:stats’:
chisq.test, fisher.test
[1] "2009-07-06"
[1] "2009-07-06"
[1] "2009-07-06"
[1] "2020-02-29" "2009-07-06"
[1] "2009-07-06 00:00:00 UTC" "2009-07-06 02:24:00 UTC"
[3] "2009-07-06 00:00:00 UTC" NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.