Understand and be able to describe the differences in R's data structures and when each is most appropriate for a given task
Explore purrr::map
and its variants, how they relate to base R functions, and why the {purrr} variants are often preferable.
Work with lists and list columns using purrr::nest
and purrr:unnest
Understand and be able to describe the differences in R's data structures and when each is most appropriate for a given task
Explore purrr::map
and its variants, how they relate to base R functions, and why the {purrr} variants are often preferable.
Work with lists and list columns using purrr::nest
and purrr:unnest
dplyr::rowwise()
can help you avoid some of the aboveTwo labs on iteration and one on functions
Lab | Date Assigned | Date Due | Topic |
---|---|---|---|
1 | Wed, April 07 | Wed, April 14 | Subsetting lists and base R for() loops |
2 | Wed, April 14 | Wed, April 21 | Multiple models and API calls with {purrr} |
3 | Mon, May 10 | Mon, May 17 | Create and apply functions |
Two parts:
Small quiz on canvas to demonstrate knowledge (4/21; 10 points)
Take-home portion to demonstrate ability to write the correct code (assigned 4/21; 60 points)
Group project: 3-5 people
Shared GitHub repo
Fairly long - but the only homework assignment you have
Divide it up to ease the workload, then just check each other's work
Already posted!
5 parts
Component | Points | Due |
---|---|---|
Groups Finalized | 0 | 4/07/21 |
Outline | 5 | 4/21/21 |
Draft | 10 | 5/19/21 |
Peer review | 15 | 5/26/21 |
Product | 70 | 6/09/21 (11:59 pm) |
No code is used repetitively (no more than twice) 10 points
More than one variant of purrr::map
is used 5 points
At least one {purrr} function outside the basic map
family (walk_*
,
reduce
, modify_*
, etc.) 5 points
At least one instance of parallel iteration (e.g., map2_*
, pmap_*
) 5 points
No code is used repetitively (no more than twice) 10 points
More than one variant of purrr::map
is used 5 points
At least one {purrr} function outside the basic map
family (walk_*
,
reduce
, modify_*
, etc.) 5 points
At least one instance of parallel iteration (e.g., map2_*
, pmap_*
) 5 points
At least one use case of purrr::nest %>% mutate()
5 points
At least two custom functions 20 points; 10 points each
Code is fully reproducible and housed on GitHub 10 points
At least two custom functions 20 points; 10 points each
Code is fully reproducible and housed on GitHub 10 points
No obvious errors in chosen output format 5 points
At least two custom functions 20 points; 10 points each
Code is fully reproducible and housed on GitHub 10 points
No obvious errors in chosen output format 5 points
Deployed on the web and shareable through a link 5 points
Expected to still be a work in progress
Direction should be obvious
Most, if not all, grading elements should be present
Provided to your peers so they can learn from you as much as you can learn from their feedback
Lower percent | Lower point range | Grade | Upper point range | Upper percent |
---|---|---|---|---|
0.97 | (194 pts) | A+ | ||
0.93 | (186 pts) | A | (194 pts) | 0.97 |
0.90 | (180 pts) | A- | (186 pts) | 0.93 |
0.87 | (174 pts) | B+ | (180 pts) | 0.90 |
0.83 | (166 pts) | B | (174 pts) | 0.87 |
0.80 | (160 pts) | B- | (166 pts) | 0.83 |
0.77 | (154 pts) | C+ | (160 pts) | 0.80 |
0.73 | (146 pts) | C | (154 pts) | 0.77 |
0.70 | (140 pts) | C- | (146 pts) | 0.73 |
F | (140 pts) | 0.70 |
Discuss in small breakout groups
What are the four basic types of atomic vectors?
What function creates a vector?
T/F: A list (an R list) is not a vector.
What is the fundamental difference between a matrix and a data frame?
What does coercion mean, and when does it come into play?
05:00
Vectors are created with c
. Below are examples of each of the four main types
of vectors.
# L explicitly an integer, not doubleinteger <- c(5L, 7L, 3L, 94L) double <- c(3.27, 8.41, Inf, -Inf)logical <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE)character <- c("red", "orange", "yellow", "green", "blue", "violet", "rainbow")
Each element of the list is another vector, possibly atomic, possibly not
The prior example included all scalar vectors
Lists do not require all elements to be the same length
list( c("a", "b", "c"), rnorm(5), c(7L, 2L), c(TRUE, TRUE, FALSE, TRUE))
## [[1]]## [1] "a" "b" "c"## ## [[2]]## [1] 1.3538821 1.0832340 -1.7026819 2.3283768 -0.8370443## ## [[3]]## [1] 7 2## ## [[4]]## [1] TRUE TRUE FALSE TRUE
Atomic vectors must all be the same type
Lists are also vectors, but not atomic vectors
Each element can be of a different type and length
Incredibly flexible, but often a little more difficult to get the hang of
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |