-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro-r.R
More file actions
118 lines (93 loc) · 3.02 KB
/
Copy pathintro-r.R
File metadata and controls
118 lines (93 loc) · 3.02 KB
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
#install.packages('tidyverse')
library(tidyverse) #cmd + enter
install.packages('nycflights13')
library(nycflights13)
View(flights)
alaska_flights <- flights %>%
filter(carrier == "AS")
head(alaska_flights)
tail(alaska_flights)
glimpse(alaska_flights)
ggplot(data = alaska_flights, mapping = aes(x = dep_delay, y = arr_delay)) +
geom_point(alpha = 0.2)
ggplot(data = alaska_flights, mapping = aes(x = distance, y = air_time)) +
geom_point(alpha = 0.2)
ggplot(data = alaska_flights, mapping = aes(x = sched_dep_time, y = dep_time)) +
geom_point(alpha = 0.2)
ggplot(data = alaska_flights, mapping = aes(x = dep_time, y = dep_delay)) +
geom_point(alpha = 0.2)
#Create a new scatterplot using different variables in the `alaska_flights`
#data frame by modifying the example above.
ggplot(data = alaska_flights, mapping = aes(x = dep_delay, y = arr_delay)) +
geom_jitter(width = 60, height = 40)
View(weather)
early_january_weather <- weather %>%
filter(origin == "EWR" & month == 1 & day <= 15)
ggplot(data = early_january_weather, mapping = aes(x = time_hour, y = temp)) +
geom_line()
#Plot a time series of a variable other than temp for Newark Airport in the
# first 15 days of January 2013.
ggplot(data = early_january_weather, mapping = aes(x = time_hour, y = humid)) +
geom_line()
ggplot(weather, aes(x = temp)) +
geom_histogram()
ggplot(weather, aes(x = temp)) +
geom_histogram(binw =30, color = 'white', fill = 'steelblue')
ggplot(weather, aes(x = temp)) +
geom_histogram(binw =60, color = 'white', fill = 'steelblue')
myplot <- ggplot(weather, aes(x = temp)) +
geom_histogram(binwidth = 5, color = "white") +
facet_wrap(~ month, nrow=3)
1 + 100
3 + 5 * 2
(3 + 5) * 2
2/10000
sin(1)
log(1)
1 == 1
1 != 2
1 < 2
x <- 1/40
x
periods.between.words
underscores_between_words
camelCaseToSeparateWords
1:5
2^(1:5)
x <- 1:5
2^x
ls()
rm(x)
ls()
rm(list = ls())
x <- 1/40
alaska_flights$dep_delay
typeof(alaska_flights$carrier)
typeof(3.14)
portland_flight <- flights %>%
filter(dest == "PDX")
#To see many of these in action, let’s select all flights that left
#JFK airport heading to Burlington, Vermont ("BTV") or Seattle,
#Washington ("SEA") in the months of October, November, or December.
btv_sea_flights_fall <- flights %>%
filter(origin == "JFK", dest == "BTV" | dest == "SEA",
month >= 10)
not_btv_sea_flights_fall2 <- flights %>%
filter(!(dest == "BTV" | dest = "SEA"))
many_airports <- flights %>%
filter(dest == "BTV" | dest == "SEA" | dest == "PDX" | dest == "SFO" | dest == "BDL")
many_airports <- flights %>%
filter(dest %in% c("BTV", "SEA", "PDX", "SFO", "BDL"))
summary_temp <- weather %>%
summarize(mean = mean(temp, na.rm = TRUE),
std_dev = sd(temp, na.rm = TRUE))
summary_temp
summary_monthly_temp <- weather %>%
group_by(month) %>%
summarise(mean = mean(temp, na.rm = T),
std_dev = sd(temp, na.rm = T))
by_origin_monthly <- flights %>%
group_by(origin, month) %>%
summarise(count = n())
flights <- flights %>%
mutate(gain = dep_delay - arr_delay)