#<REPLACE THIS COMMENT WITH YOR ANSWER>
Lab 6. Loops and Apply
Introduction
Click here to access the lab on Github Classroom: Github Classroom Assignment for Lab 6: Loops and Apply
Both for()
loops and the apply functions greatly expand the amount of data we are able to work with. Combined with our new knowledge of functions, these tools drastically increase what we are able to do in our analyses. Today we will be practicing working with more dynamic data formats–going beyond a single dataframe.
The Data
The data we will be using today comes from PEN America’s Book Bans database. This database attempts to catalog all books banned in US schools between July 2021 and June 2022. While it is impossible to know if this is all of the bans, and it does not account for books being un-banned later, it is still quite the dataset to look through.
I’ve provided a CSV version of the database in the data/
directory of this project, as well as a copy of the data documentation in the docs/
directory. Be sure to refer to it as you work.
Tidying the Title
We have some un-tidy data in our banned books dataframe, namely that the Title
column contains both the title, and the title of the series if it is part of one. We should fix that.
#<REPLACE THIS COMMENT WITH YOR ANSWER>
#<REPLACE THIS COMMENT WITH YOR ANSWER>
Splitting the Data
We’re going to be doing some analyses by state in this lab, so our first step will be splitting the data into multiple dataframes. Rather than typing out and sub-setting each manually, we will use a for()
loop to do so.
#<REPLACE THIS COMMENT WITH YOR ANSWER>
Analysis by State
Now we are going to perform some data manipulation by state. We are going to use lapply()
and a custom function to get some highlights per state.
#<REPLACE THIS COMMENT WITH YOR ANSWER>