Peter Rabinovitch
2023-01-24
One advantage to submitting early is that if I have time, I can have a look and provide feedback before it is due.
Example: can’t figure out how to exclude rows with filter
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ purrr 1.0.0 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## New names:
## • `` -> `...3`
## # A tibble: 6 × 4
## Precinct Registe…¹ ...3 Cards…²
## <chr> <dbl> <lgl> <dbl>
## 1 Spc Adv 4 99-002 - City Hall 0 NA 487
## 2 Spc Adv 4 99-003 - Greenboro Community Centre 0 NA 515
## 3 Spc Adv 4 99-004 - Ben Franklin Place 0 NA 600
## 4 Spc Adv 4 99-005 - Minto Recreation Complex-Barrhaven 0 NA 620
## 5 Spc Adv 4 99-006 - Richcraft Recreation Complex-Kanata 0 NA 501
## 6 City / Ville - Total 633946 NA 269772
## # … with abbreviated variable names ¹`Registered\nVoters`, ²`Cards Cast`
df <- tribble(~precinct, ~votes, #input
"99-002 - City Hall",0,
"99-003 - Greenboro Community Centre", 515,
"99-006 - Richcraft Recreation Complex-Kanata",501,
"City / Ville - Total", 633946
)
# want
# precinct votes
# 1 99-002 - City Hall 0
# 2 99-003 - Greenboro Community Centre 515
# 3 99-006 - Richcraft Recreation Complex-Kanata 501
df %>% filter(str_detect(precinct, 'city'))
## # A tibble: 0 × 2
## # … with 2 variables: precinct <chr>, votes <dbl>
## # A tibble: 2 × 2
## precinct votes
## <chr> <dbl>
## 1 99-002 - City Hall 0
## 2 City / Ville - Total 633946
## # A tibble: 2 × 2
## precinct votes
## <chr> <dbl>
## 1 99-003 - Greenboro Community Centre 515
## 2 99-006 - Richcraft Recreation Complex-Kanata 501
Note: frequently the act of reducing your problem to minimal reproducible example will help you figure out what the problem is
Also: if you have to compress you example use a format that can be decompressed free and commonly (i.e. zip). Do not require your helper to install or buy software.
{r, warning=FALSE, message=FALSE, error=TRUE,eval=TRUE,
fig.height=300px}
See https://kbroman.org/knitr_knutshell/pages/Rmarkdown.html
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
open code_walkthrough.R
open Stats_New_1.Rmd
open Stats_Coin_Tossing.R