HW3

Homework 3

Adam Wheeler
2022-01-02

Read in the data set

# knitr::opts_chunk$set(echo = FALSE)
library(dplyr)
library(tidyverse)
library(readxl)

organic <- read_excel(
  path = "../Downloads/organiceggpoultry.xlsx",
  skip = 4
)

Tidy the data set

# name column to make it mutable
colnames(organic)[1] = "Date"

organic <- organic %>%
  # drop empty column
  select(-6) %>%
  # remove extra characters from Date
  mutate(Date = ifelse(grepl("/", Date), gsub(".{3}$", "", Date), Date)) %>%
  # separate Date into month and year variables
  separate(Date, sep = " ", into = c("Month", "Year")) %>%
  # fix abbreviated month name
  mutate(Month = str_replace(Month, "Jan", "January")) %>%
  # fill in missing year values
  fill(Year) %>%
  # convert mutated variables as numeric values (and replace strings with na)
  mutate(Year = as.numeric(Year)) %>%
  mutate(across(3:11, as.numeric))

head(organic)
# A tibble: 6 x 11
  Month     Year `Extra Large \nD~ `Extra Large 1/2 D~ `Large \nDozen`
  <chr>    <dbl>             <dbl>               <dbl>           <dbl>
1 January   2004              230                 132             230 
2 February  2004              230                 134.            226.
3 March     2004              230                 137             225 
4 April     2004              234.                137             225 
5 May       2004              236                 137             225 
6 June      2004              241                 137             231.
# ... with 6 more variables: Large 
1/2 Doz. <dbl>, Whole <dbl>,
#   B/S Breast <dbl>, Bone-in Breast <dbl>, Whole Legs <dbl>,
#   Thighs <dbl>

Explain the variables

cols(
  `Extra Large Dozen` = col_double(),
  `Extra Large 1/2 Doz.` = col_double(),
  `Large Dozen` = col_double(),
  `Large 1/2 Doz.` = col_double(),
  `Whole` = col_double(),
  `B/S Breast` = col_double(),
  `Bone-in Breast` = col_double(),
  `Whole Legs` = col_double(),
  `Thighs` = col_double(),
  `Month` = col_character(),
  `Year` = col_integer()
)

Identify research questions

How much did price fluctuate for each product between 2004 and 2013?

How did product prices rank or compare with each other over these years?

Reuse

Text and figures are licensed under Creative Commons Attribution CC BY-NC 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".

Citation

For attribution, please cite this work as

Wheeler (2022, Jan. 3). Data Analytics and Computational Social Science: HW3. Retrieved from https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomabwheelhw3/

BibTeX citation

@misc{wheeler2022hw3,
  author = {Wheeler, Adam},
  title = {Data Analytics and Computational Social Science: HW3},
  url = {https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomabwheelhw3/},
  year = {2022}
}