-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathr_session.txt
196 lines (196 loc) · 3.7 KB
/
r_session.txt
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
list.files()
w = read.csv("data/noaa_daily.csv")
dogs = readRDS("data/dogs.rds")
dogs
table(dogs$breed)
dotplot(table(dogs$breed))
dotchart(table(dogs$breed))
dotchart(as.numeric(table(dogs$breed)))
x11()
dotchart(as.numeric(table(dogs$breed)))
dev.off()
dotchart(as.numeric(table(dogs$breed)))
dotchart(as.numeric(table(dogs$breed)))
mar = par("mar")
par(mar = 0)
par(mar = rep(0, 4))
dotchart(as.numeric(table(dogs$breed)))
par(mar = rep(2, 4))
dotchart(as.numeric(table(dogs$breed)))
dotchart(c(table(dogs$breed)))
tab = c(table(dogs$breed))
names(tab)
names(tab) = c("X", "Y", "Z")
dotchart(tab)
dogs = readRDS("data/dogs.rds")
dogs
table(dogs$breed)
tab = table(dogs$breed)
dotchart(tab)
tab = c(table(dogs$breed))
tab
dotchart(tab)
mar = par("mar")
mar
par(mar = c(2, 2, 2, 2))
dotchart(tab)
dotchart(tab, yaxt = 'n')
tab
names(tab) = c("Tiny Dog", "Happy Dog", "Fluffy Dog")
tab
dotchart(tab)
names(tab) = NA
tab
dotchart(tab)
w = read.csv("data/noaa_daily.csv")
head(w)
san = subset(w, station == "San Diego, CA")
mean(san$tmax)
dogs
split(dogs, dogs$breed)
spl = split(dogs, dogs$breed)
spl$Poodle
spl_w = split(w, w$station)
names(spl_w)
spl_w$Barcelona
head(spl_w$Barcelona)
names(spl_w)
spl_w$Honolulu, HI
spl_w$"Honolulu, HI"
temps = split(w$tmax, w$station)
names(temps)
sapply(temps, mean)
sapply(temps, mean, na.rm = T)
5 / 0
names(spl_w)
sapply(spl_w, head)
head(spl_w$Barcelona)
spl
unsplit(spl, dogs$breed)
function(x) x^2
sq = function(x) x^2
sq(2)
sq(x = 3)
sq(y = 10)
sq()
to_celsius = function(farenheit) {
celsius = (farenheit - 32) * (5 / 9)
celsius
}
to_celsius(76)
to_celsius(90)
to_celsius = function(farenheit) {
celsius = (farenheit - 32) * (5 / 9)
return(celsius)
"Farenheit is cooler than celsius!"
}
to_celsius(32)
to_celsius = function(farenheit) {
(farenheit - 32) * (5 / 9)
}
to_celsius(32)
sin(c(1, 2, 3))
to_celsius(c(76, 32, 90))
sq()
sq = function(x = 9) x^2
sq()
sq(2)
pct_diff = function(x, ref) {
diff = x - ref
diff / ref
}
pct_diff(3, 2)
pct_diff = function(x, ref = 10) {
diff = x - ref
diff / ref
}
pct_diff(3)
sq(y = 10)
third = function(a, b, c, d, e) {
c
}
third(1, 2, 3, 4, 5)
third(c = -5, a = 1, b = 7, d = 10, e = 9)
third(1, 2, 3, e = 4, d = 5)
big_river = "none"
davis = function() {
big_river = "putah creek"
big_river
}
davis()
needles = function() {
big_river
}
needles()
las_vegas = function() {
casino
}
las_vegas()
davis = function(big_river = "putah creek") {
big_river
}
davis()
davis("oh no the sac river levy flooded")
davis = function() {
grocery = "Nugget"
grocery
}
davis()
grocery
dogs
x = c(3, 2, 4)
sin(x)
lapply(x, sin)
spl
standardized_speed = function(x) {
mean(x$speed / x$age)
}
spl$Poodle
standardized_speed(spl$Poodle)
lapply(spl, standardized_speed)
dogs
standardized_speed = function(x) {
mean(x$speed / x$age, na.rm = T)
}
lapply(spl, standardized_speed)
typeof(dogs)
dogs
lapply(dogs, class)
lapply(dogs, sd)
lapply(dogs[1:2], sd)
lapply(dogs[1:2], sd, na.rm = T)
standardized_speed = function(x, mult = 1) {
mean(x$speed / x$age, na.rm = T) * mult
}
lapply(spl, standardized_speed)
lapply(spl, standardized_speed, 100)
lapply(dogs[1:2], sd)
sapply(dogs[1:2], sd)
spl_sex = split(dogs, dogs$sex)
spl_sex
sapply(spl_sex, mean)
spl_sex = split(dogs$speed, dogs$sex)
sapply(spl_sex, mean)
by_station = split(w$tmax, w$station)
sapply(by_station, mean)
sapply(by_station, mean, na.rm = T)
tapply(w$tmax, w$station, mean, na.rm = T)
foo = function(x, y) {
(x - y) / (x + y)
}
foo(2, 3)
x = c(1, 2, 3, 4)
y = c(5, 7, 9, 8)
a = c(1, 2, 3, 4)
b = c(5, 7, 9, 8)
mapply(foo, a, b)
foo(1, 5)
foo(2, 7)
tapply(w$tmax, w$station, mean, na.rm = T)
aggregate(w$tmax, w$station, mean)
?aggregate
aggregate(w$tmax, list(w$station), mean)
spl$Poodle
poodle = spl$Poodle
poodle$speed / poodle$age
mean(poodle$speed / poodle$age)