Manipulating Time Series Data in R
Harrison Brown
Graduate Researcher in Geography
Order of day, month, and year:
12/20/2022
20/12/2022
6/4/2010
: June 4th or April 6th?
"Time elements":
2022-06-04
2022-06-04
= June 4th, 2022-
) between date elements2022-06-04
2022-06-04
vs. 20220604
lubridate::parse_date_time()
earthday <- "April 22, 2022"
parse_date_time(earthday,
orders = "%B %d, %Y")
[1] "2022-08-22 UTC"
?strptime
to view conversion specifications
Common conversion specifications:
Time Element | Conversion Spec. |
---|---|
Year (YYYY ) |
%Y |
Year (yy ) |
%y |
Day (dd ) |
%d |
Month (mm ) |
%m |
Month (August) | %B |
Month (Aug) | %b |
dates_vector <- c("12/20/2022",
"2022-12-21",
"December 22, 2022")
dates_vector
[1] "12/20/2022"
[2] "2022-12-21"
[3] "December 22, 2022"
library(lubridate)
parse_date_time(
dates_vector,
orders = c("%m/%d/%Y",
"%Y-%m-%d",
"%B %d, %Y"))
[1] "2022-12-20 UTC"
[2] "2022-12-21 UTC"
[3] "2022-12-22 UTC"
Manipulating Time Series Data in R