-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy path.Rhistory
79 lines (79 loc) · 3.11 KB
/
.Rhistory
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
# Week 1 - Introduction to R
library(tidyverse)
# load data
data <- read_csv("data.csv")
knitr::opts_chunk$set(echo = TRUE)
summary(cars)
plot(pressure)
source("~/.active-rstudio-document", echo=TRUE)
nycflights13
def.chunk.hook <- knitr::knit_hooks$get("chunk")
knitr::knit_hooks$set(chunk = function(x, options) {
x <- def.chunk.hook(x, options)
#ifelse(options$size != "a", paste0("\n \\", "tiny","\n\n", x, "\n\n \\normalsize"), x)
ifelse(options$size != "normalsize", paste0("\n \\", options$size,"\n\n", x, "\n\n \\normalsize"), x)
})
knitr::opts_chunk$set(echo = FALSE, dev = "png") # NOTE: switched to png instead of pdf to decrease size of the resulting pdf
library(tidyverse)
library(nycflights13)
library(kableExtra)
# read in the data
data <- read_csv("data.csv")
library(nycflights13)
nycflights13
head(nycflights13)
flights
library(lubridate)
flights$date <- as_date(paste0(flights$year, "-", flights$month, "-", flights$day))
flights
flights$date
?as_datetime
hour(530)
hour(530, tz = tz("EST"))
flights$dep_time %/% 100
flights$dep_time %% 100
date$dep_time
flights$date
flights$dep_time
as_date(paste0(flights$year, "-", flights$month, "-", flights$day, " ", flights$dep_time %/% 100, ":", flights$dep_time %% 100))
?%/%
?"%/%"
dmy_hm(paste0(flights$year, "-", flights$month, "-", flights$day, " ", flights$dep_time %/% 100, ":", flights$dep_time %% 100))
hm(flights$dep_time)
paste0(flights$dep_time %/% 100, ":", flights$dep_time %% 100)
flights$dep_time
library(nycflights13)
sprintf("%02d:%02d", flights$dep_time %/% 100, flights$dep_time %% 100)
hm(sprintf("%02d:%02d", flights$dep_time %/% 100, flights$dep_time %% 100))
flights
minutes(flights$dep_delay)
flights$dep_delay_new <- minutes(flights$dep_delay)
flights %>%
group_by(origin) %>% # this groups ROWS based on their origin value
summarize(avg_dep_delay = mean(dep_delay_new, na.rm = T)) # this summarizes the data, creating means absed on the grouping!
flights %>%
group_by(origin) %>% # this groups ROWS based on their origin value
summarize(avg_dep_delay = mean(dep_delay, na.rm = T)) # this summarizes the data, creating means absed on the grouping!
as.duration(flights$dep_delay)
as.duration(flights$dep_delay, unit = "mins")
flights$dep_delay_new <- as.duration(flights$dep_delay, unit = "minutes")
as.duration(flights$dep_delay, unit = "minute")
duration(flights$dep_delay, unit = "minute")
mean(flights$dep_delay_new)
mean(flights$dep_delay_new, na.rm = TRUE)
flights$dep_delay_new <- period(flights$dep_delay, unit = "minute")
flights$dep_delay_new
flights$dep_delay_new <- period(flights$dep_delay, units = "minute")
flights$dep_delay_new
flights$dep_delay_new <- as.period(flights$dep_delay, units = "minute")
flights$dep_delay_new
flights$dep_delay_new <- as.period(flights$dep_delay, unit = "minute")
flights$dep_delay_new
flights$dep_delay_new <- as.duration(flights$dep_delay, unit = "minute")
flights$dep_delay_new <- as.duration(flights$dep_delay, units = "minute")
flights$dep_delay_new <- duration(flights$dep_delay, unit = "minute")
flights$dep_delay_new
flights$dep_delay_new <- as.period(flights$dep_delay, unit = "minute")
flights$dep_delay_new
minutes(flights$dep_delay_new)
?head