-
Notifications
You must be signed in to change notification settings - Fork 12
/
013-parallel-processing.qmd
83 lines (60 loc) · 1.67 KB
/
013-parallel-processing.qmd
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
---
title: "Parallel processing in R"
author: "Jeff Oliver"
date: "`r format(Sys.time(), '%d %B, %Y')`"
---
```{r library-check, echo = FALSE, results = "hide"}
#| output: false
libs <- c("randomForest", "dplyr")
libs_missing <- libs[!(libs %in% installed.packages()[, "Package"])]
if (length(libs_missing) > 0) {
for (l in libs_missing) {
install.packages(l)
}
}
```
[INTRODUCTORY SENTENCE]
#### Learning objectives
1. Use `for` loop syntax to repeat operations
2. Apply built-in functions for more efficient repetition
3. Implement processes in parallel to reduce computation time
## [DESCRIPTION OR MOTIVATION; 2-4 sentences that would be used for an announcement]
***
## Getting started
***
## Repeating things
```{r}
# Sampling
# https://www.census.gov/quickfacts/fact/table/US/LFE046217
prop.women <- 0.582
random.draw <- sample(x = c("female", "male"),
size = 500,
replace = TRUE,
prob = c(prop.women, 1 - prop.women))
table(random.draw)
prop.latinx <- 0.183
random.draw <- sample(x = c("latinx", "not"),
size = 500,
replace = TRUE,
prob = c(prop.latinx, 1 - prop.latinx))
table(random.draw)
# Observed Fortune 500 U.S. CEOs
f500.women <- 33
f500.latinx <- 11
# For loop, 1000 replicates to build distribution
```
***
## Repeating things faster
```{r}
# use sapply or lapply instead of for loop
```
***
## Don't wait in line
```{r}
# replace s/lapply with parS/Lapply
```
***
## Additional resources
+ [resource one](url-one)
+ [resource two](url-two)
+ A [PDF version](https://jcoliver.github.io/learn-r/lesson-name.pdf) of this lesson