challenge_4
poultry_tidy
More data wrangling: pivoting
Author

Lindsay Jones

Published

August 18, 2022

Code
library(tidyverse)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Read in data

Code
poultry_tidy <- read_csv("_data/poultry_tidy.csv",
                         show_col_types = FALSE)

Briefly describe the data

Data set shows the price in dollars for 5 different cuts of poultry during each month from 2004 to 2013.

Tidy Data (as needed)

The data is NOT tidy. I will use pivot_wider to correct this.

Code
poultry_tidy_wider <- pivot_wider(poultry_tidy, 
                                  names_from = Product, 
                                  values_from = Price_Dollar)
print(poultry_tidy_wider)
# A tibble: 120 × 7
    Year Month     Whole `B/S Breast` `Bone-in Breast` `Whole Legs` Thighs
   <dbl> <chr>     <dbl>        <dbl>            <dbl>        <dbl>  <dbl>
 1  2013 January    2.38         7.04             3.90         2.04   2.16
 2  2013 February   2.38         7.04             3.90         2.04   2.16
 3  2013 March      2.38         7.04             3.90         2.04   2.16
 4  2013 April      2.38         7.04             3.90         2.04   2.16
 5  2013 May        2.38         7.04             3.90         2.04   2.16
 6  2013 June       2.38         7.04             3.90         2.04   2.16
 7  2013 July       2.38         7.04             3.90         2.04   2.16
 8  2013 August     2.38         7.04             3.90         2.04   2.16
 9  2013 September  2.38         7.04             3.90         2.04   2.16
10  2013 October    2.38         7.04             3.90         2.04   2.16
# … with 110 more rows
# ℹ Use `print(n = ...)` to see more rows

Identify variables that need to be mutated

The year and month need to be mutated into one date.

I would like to rename the “Whole Legs” column to something not containing the word “whole” to avoid confusion with the other variable, but my attempts to rename the column didn’t work.