Skip to content

Commit c6944be

Browse files
committed
Individual slides
1 parent e28bce9 commit c6944be

22 files changed

+27
-36
lines changed

03_GettingData/dplyr/dplyr.Rmd

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
% Managing Data Frames with `dplyr`
2-
% Biostatistics 140.776
32
%
43

54
```{r, echo=FALSE, results="hide"}
@@ -177,12 +176,12 @@ Generating summary statistics by stratum
177176

178177
```{r, tidy=FALSE}
179178
chicago <- mutate(chicago,
180-
tempcat = factor(1 * (tmpd > 90),
179+
tempcat = factor(1 * (tmpd > 80),
181180
labels = c("cold", "hot")))
182181
hotcold <- group_by(chicago, tempcat)
183182
summarize(hotcold, pm25 = mean(pm25, na.rm = TRUE),
184-
o3 = max(o3tmean2, na.rm = TRUE),
185-
no2 = median(no2tmean2, na.rm = TRUE))
183+
o3 = max(o3tmean2),
184+
no2 = median(no2tmean2))
186185
```
187186

188187

@@ -207,15 +206,15 @@ chicago$year <- NULL ## Can't use mutate to create an existing variable
207206
# `%>%`
208207

209208
```{r,tidy=FALSE,eval=FALSE}
210-
chicago %>% mutate(year = as.POSIXlt(date)$year + 1900)
211-
%>% group_by(year)
209+
chicago %>% mutate(month = as.POSIXlt(date)$mon + 1)
210+
%>% group_by(month)
212211
%>% summarize(pm25 = mean(pm25, na.rm = TRUE),
213212
o3 = max(o3tmean2, na.rm = TRUE),
214213
no2 = median(no2tmean2, na.rm = TRUE))
215214
```
216215

217216
```{r,echo=FALSE}
218-
chicago %>% mutate(year = as.POSIXlt(date)$year + 1900) %>% group_by(year) %>%
217+
chicago %>% mutate(month = as.POSIXlt(date)$mon + 1) %>% group_by(month) %>%
219218
summarize(pm25 = mean(pm25, na.rm = TRUE), o3 = max(o3tmean2, na.rm = TRUE), no2 = median(no2tmean2, na.rm = TRUE))
220219
221220
```

03_GettingData/dplyr/dplyr.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
% Managing Data Frames with `dplyr`
2-
% Biostatistics 140.776
32
%
43

54

@@ -323,20 +322,20 @@ Generating summary statistics by stratum
323322

324323
```r
325324
chicago <- mutate(chicago,
326-
tempcat = factor(1 * (tmpd > 90),
325+
tempcat = factor(1 * (tmpd > 80),
327326
labels = c("cold", "hot")))
328327
hotcold <- group_by(chicago, tempcat)
329328
summarize(hotcold, pm25 = mean(pm25, na.rm = TRUE),
330-
o3 = max(o3tmean2, na.rm = TRUE),
331-
no2 = median(no2tmean2, na.rm = TRUE))
329+
o3 = max(o3tmean2),
330+
no2 = median(no2tmean2))
332331
```
333332

334333
```
335334
## Source: local data frame [3 x 4]
336335
##
337336
## tempcat pm25 o3 no2
338-
## 1 cold 16.21831 66.587500 24.55492
339-
## 2 hot NaN 58.549524 26.04565
337+
## 1 cold 15.97807 66.587500 24.54924
338+
## 2 hot 26.48118 62.969656 24.93870
340339
## 3 NA 47.73750 9.416667 37.44444
341340
```
342341

@@ -387,37 +386,30 @@ summarize(years, pm25 = mean(pm25, na.rm = TRUE),
387386

388387

389388
```r
390-
chicago %>% mutate(year = as.POSIXlt(date)$year + 1900)
391-
%>% group_by(year)
389+
chicago %>% mutate(month = as.POSIXlt(date)$mon + 1)
390+
%>% group_by(month)
392391
%>% summarize(pm25 = mean(pm25, na.rm = TRUE),
393392
o3 = max(o3tmean2, na.rm = TRUE),
394393
no2 = median(no2tmean2, na.rm = TRUE))
395394
```
396395

397396

398397
```
399-
## Source: local data frame [19 x 4]
398+
## Source: local data frame [12 x 4]
400399
##
401-
## year pm25 o3 no2
402-
## 1 1987 NaN 62.96966 23.49369
403-
## 2 1988 NaN 61.67708 24.52296
404-
## 3 1989 NaN 59.72727 26.14062
405-
## 4 1990 NaN 52.22917 22.59583
406-
## 5 1991 NaN 63.10417 21.38194
407-
## 6 1992 NaN 50.82870 24.78921
408-
## 7 1993 NaN 44.30093 25.76993
409-
## 8 1994 NaN 52.17844 28.47500
410-
## 9 1995 NaN 66.58750 27.26042
411-
## 10 1996 NaN 58.39583 26.38715
412-
## 11 1997 NaN 56.54167 25.48143
413-
## 12 1998 18.26467 50.66250 24.58649
414-
## 13 1999 18.49646 57.48864 24.66667
415-
## 14 2000 16.93806 55.76103 23.46082
416-
## 15 2001 16.92632 51.81984 25.06522
417-
## 16 2002 15.27335 54.88043 22.73750
418-
## 17 2003 15.23183 56.16608 24.62500
419-
## 18 2004 14.62864 44.48240 23.39130
420-
## 19 2005 16.18556 58.84126 22.62387
400+
## month pm25 o3 no2
401+
## 1 1 17.76996 28.22222 25.35417
402+
## 2 2 20.37513 37.37500 26.78034
403+
## 3 3 17.40818 39.05000 26.76984
404+
## 4 4 13.85879 47.94907 25.03125
405+
## 5 5 14.07420 52.75000 24.22222
406+
## 6 6 15.86461 66.58750 25.01140
407+
## 7 7 16.57087 59.54167 22.38442
408+
## 8 8 16.93380 53.96701 22.98333
409+
## 9 9 15.91279 57.48864 24.47917
410+
## 10 10 14.23557 47.09275 24.15217
411+
## 11 11 15.15794 29.45833 23.56537
412+
## 12 12 17.52221 27.70833 24.45773
421413
```
422414

423415

03_GettingData/dplyr/dplyr.pdf

74.4 KB
Binary file not shown.
11.7 KB
Loading
19.9 KB
Loading
23.3 KB
Loading
28.8 KB
Loading
20.9 KB
Loading
21.5 KB
Loading
27.6 KB
Loading

0 commit comments

Comments
 (0)