It’s up to you to organize your own week1-lab.qmd file (i.e. there is no template). You may (should) discuss and work through today’s exercise with a partner (or two!).
Your goal is to transform the bee stressor data into a tidy format to answer the following question: What is the average percent of bee colonies that are affected by a particular stressor in each quarter for a specific state?
Download the
stressor.csvhere. Load the{tidyverse}and{janitor}packages, and read instressor.csv. Perform some basic data exploration. Use the{here}package to read in your data and check out things like the dimensions, structure, types of variables, unique observations, etc. Read through the metadata. These data come from tidytuesday. In an effort to provide a data wrangling activity, the data was messified using themessypackage in R.Consider what data cleaning you might need to perform. Discuss any curious data formatting (e.g. data types, inconsistent observation names, missing values, etc.) that you discovered during your data exploration step, above. What might you need to address in your next data wrangling steps?
Take a moment to share some of your findings with the rest of the class.
- Clean / wrangle the data! Using the packages loaded in step 1, perform the following operations (NOTE: Each step below corresponds to a single line of code):
- Remove all special characters in the
stateandstressorcolumn observations - Convert all column names from CamelCase to snake_case (for ease of readability and to adhere to the Tidyverse style guide recommendation)
- Check the class of the
yearvariable. Update the data type if necessary. - Pivot your dataframe to make it tidy data. Remember, in tidy data:
- Each variables forms a column
- Each observation forms a row
- Each cell is a single measurement
- Create a new column named
quarterthat contains the quarter number that the observation took place in - Remove any rows where the state is “United States” or “Other States”
- Filter to select a single stressor and single state that interests you!
- Group by year and quarter to calculate the average stress level
- Create a data viz of your choice!
- Remove all special characters in the