-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateTime.Rmd
123 lines (91 loc) · 1.79 KB
/
DateTime.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
---
title: "Dates and times"
output: html_notebook
---
# Dates and Times - builtin function
ISO 8601
as.Date()
library(anytime)
anytime() - recognises US data convention not british
Jan 1st 1970 is day zero
scale_x_date(date_breaks = "10 years", date_labels = "%Y")
Sys.Date()
as.POSIXlt() - list output
as.POSIXct() - seconds since Jan 1st 1970
POSIX - Portable Operating System Interface
##timezones
UTC - Coordinated Universal Time/Local
tz
# lubridate
specific function
ymd() - family corresponding to different orders
dmy_hms() - also handles datetime
parse_date_time() - general function - can pass a string of orders
make_date() - specify date from components
make_datetime()
## extracting parts of dates
year()
month()
day()
hour()
min()
second()
wday()
yday()
tz()
leap_year()
am()
pm()
dst()
quarter()
semester()
## Rounding
Useful in similar situations to extraction, but preserves the context of the unit
round_date()
ceiling_date()
floor_date()
#Arithmetic with datetimes
difftime()
now()
today()
## time spans
### period - human intuition of time
days()
### duration - stopwatch view of time
ddays()
synodic month
Saros
#### sequences of dates
today() + 1:10*days
%m+%
%m-%
add_with_rollback()
### Intervals (3rd option)
best choice when you have start and end
%--%
interval()
int_start()
int_end()
int_length()
as.period()
as.duration()
%within%
int_overlaps()
# Other stuff
## Time zones
Sys.timezone()
IANA timezones - Arthur David Olson
OlsonNames()
force_tz() - same clock time, different timezone
with_tz() - view same time in different timezone
## Times without dates
library(hms)
## Speed
library(fasttime)
fastPOSIXct()
lubridate::fast_strptime()
write_csv() knows how to handle output in ISO format
stamp()
compare processing time:
library(microbenchmark)
microbenchmark()