Assignment 3
Due: Monday, June 2 at 11 AM ET to be submitted via Crowdmark
Note: Your submitted solution must be unique and written in your own words; if you collaborate with other students, external resources, and/or use AI tools, this must be clearly acknowledged in your submission.
Part 1
This assignment covers material from Chapters 15-21 of R4DS / Chapters 18-24 of P4DS. For P4DS readers, please also read the merging documentation from pandas. Please complete the ALL of following exercises.
First, acquire the following data, which can be read directly from the url using read_csv.
gss_cat(for Python users, please convertrincomeandpartyidto categories)
Questions
What word in
wordshas the most vowels? Which word has the highest proportion of vowels? (Hint: what is the denominator?)From
wordscreate regular expressions that find all words that:Start with “y”.
Don’t start with “y”.
End with “x”.
Are exactly three letters long.
Have seven letters or more.
Contain a vowel-consonant pair.
Contain at least two vowel-consonant pairs in a row.
Only consist of repeated vowel-consonant pairs.
Switch the first and last letters of all of the words in
words. Which of those strings are still found inwords?Using the
gss_catdataset, explore the distribution ofrincome(reported income). What makes the default bar chart hard to understand? How could you improve the plot?Categorize
partyidinto{democrat, republican, independent, other}. How have the proportions of people identifying as Democrat, Republican, and Independent changed over time?Parse the following date-times:
d1 = "January 1, 2010" d2 = "2015-Mar-07" d3 = "06-Jun-2017" d4 = "August 19 (2015)" d5 = "12/30/14" # Dec 30, 2014 t1 = "1705" t2 = "11:15:10.12 PM"Revisit the
flightsdataset.- How does the distribution of flight times within a day change over the course of the year?
- On what day of the week should you leave if you want to minimise the chance of a delay?
- Use joins to find all flights to the 10 most popular destinations in
flights. - Find the 48 hours (over the course of the whole year) that have the worst delays. Cross-reference it with the
weatherdata. Can you see any patterns?
What is
dplyr::distinct()/pd.drop_duplicates()translated to in SQL? What abouthead()?
Part 2
Using a sports dataset from a library/package of your choice, perform the following steps of the data science workflow:
- Tidy
- Is your data tidy? If so, please briefly describe why, and if not, please describe the steps that need to be taken to make it tidy, such as separating columns that combine multiple variables or modifying column names.
- Identify whether your data is in “long” format or “wide” format. Using a subset of the columns from your data, convert your dataset from one format to the other.
- For example, if you have play-by-play data in a long format, you can aggregate the values in a column by quarter/period/half and then make it wider.
- Transform.
- Use regular expressions and string manipulation to convert the surname of each athlete to all capital letters.
- If applicable, perform appropriate date-time manipulation to have such variables in ISO 8601 format.
- If applicable, identify missing values in the dataset and interpret why these values may be missing.
- Use logical conditions (boolean variables) to filter rows based on a specific criterion.