forked from harris-coding-lab/harris-coding-lab.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_if_statements.R
50 lines (35 loc) · 1.64 KB
/
03_if_statements.R
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
mrc_data %>%
summarise(missing_sat_2013 = sum(is.na(sat_avg_2013)))
before <- tibble(fake_data = c(1, 2, NA))
after <- before %>% mutate(missing_fake_data = ifelse(is.na(fake_data), 1, 0),
fake_data = ifelse(is.na(fake_data), mean(fake_data, na.rm = TRUE), fake_data))
## -------------------------------------------------------------------------------------------------------
before <- tibble(fake_data = c(1, 2, NA))
before
after
## -------------------------------------------------------------------------------------------------------
mrc_data %>% distinct(tier_name)
mrc_data %>% filter(1330 <= sat_avg_2013, sat_avg_2013 <= 1530)
mrc_data %>% filter(between(sat_avg_2013, 1330, 1530))
# This is pseudo code
mrc_data %>%
mutate(abdul_choices = ifelse(CONDITIONS, yes, no),
stephens_choices = ifelse(CONDITIONS, yes, no),
...) %>%
filter(abdul_choices == yes, stephens_choices == yes, ...)
mrc_data %>%
mutate(abdul_choices = ifelse(CONDITIONS, TRUE, FALSE),
stephens_choices = ifelse(CONDITIONS, TRUE, FALSE),
...) %>%
filter(abdul_choices, stephens_choices, ...)
bff_super_awesome_college_list <-
mrc %>%
mutate(abdul_choices = ifelse(between(sat_avg_2013, 1330, 1530) &
(tier_name == "Ivy Plus" | ... ), TRUE, FALSE),
sam_choices = ifelse(..., ..., ...),
nancy_choices = ifelse(..., ..., ...),
rei_choices = ifelse(..., ..., ...),
casey_choices = ifelse(..., ..., ...)
)
bff_super_awesome_college_list %>%
filter(abdul_choices, sam_choices, nancy_choices, rei_choices, cary_choices)