Ethan Campbell HW2

Importing clean dataset into R.

Ethan campbell
2022-02-09

Importing dataset in as Poultry and inspecting the data.

Here we notice we different types of data and the dimensions. Product is a character, year is an integer, month is character, and Price_dollar is a double class with numeric data and decimals.

Poultry <- read.csv("poultry_tidy.csv")
colnames(Poultry)
[1] "Product"      "Year"         "Month"        "Price_Dollar"
dim(Poultry)
[1] 600   4
head(Poultry)
  Product Year    Month Price_Dollar
1   Whole 2013  January        2.385
2   Whole 2013 February        2.385
3   Whole 2013    March        2.385
4   Whole 2013    April        2.385
5   Whole 2013      May        2.385
6   Whole 2013     June        2.385

Beginning to analyze and adjust the data.

Using filter and arrange on the data to filter out the lower cost items then placing price and year in descending order.With this we are able to view which items are higher in price and sort them by year and month.There are two functions however, one displays the top five of the table and the second one displays the last five of the table.

data(Poultry)
Poultry %>%
  filter(Price_Dollar > 3) %>%
  arrange(desc(Price_Dollar, Year)) %>%
  head()
     Product Year    Month Price_Dollar
1 B/S Breast 2013  January       7.0375
2 B/S Breast 2013 February       7.0375
3 B/S Breast 2013    March       7.0375
4 B/S Breast 2013    April       7.0375
5 B/S Breast 2013      May       7.0375
6 B/S Breast 2013     June       7.0375
data(Poultry)
Poultry %>%
  filter(Price_Dollar > 3) %>%
  arrange(desc(Price_Dollar, Year)) %>%
  tail()
           Product Year     Month Price_Dollar
229 Bone-in Breast 2004      July        3.905
230 Bone-in Breast 2004    August        3.905
231 Bone-in Breast 2004 September        3.905
232 Bone-in Breast 2004   October        3.905
233 Bone-in Breast 2004  November        3.905
234 Bone-in Breast 2004  December        3.905

Using filter and arrange

This will filter out the higher cost items and then placing year and price in descending order. With this information we can accuratly track the price change for each item by month and year. Once more using two equations to display the top five and the bottom five.

Poultry %>%
  filter(Price_Dollar < 3) %>%
  arrange(desc(Year, Price_Dollar)) %>%
  head()
  Product Year    Month Price_Dollar
1   Whole 2013  January        2.385
2   Whole 2013 February        2.385
3   Whole 2013    March        2.385
4   Whole 2013    April        2.385
5   Whole 2013      May        2.385
6   Whole 2013     June        2.385
Poultry %>%
  filter(Price_Dollar < 3) %>%
  arrange(desc(Year, Price_Dollar)) %>%
  tail()
    Product Year     Month Price_Dollar
354  Thighs 2004      July        1.995
355  Thighs 2004    August        1.995
356  Thighs 2004 September        1.995
357  Thighs 2004   October        1.995
358  Thighs 2004  November        1.995
359  Thighs 2004  December        1.995

Visulaization

We assign the cheaper products to Cheap_poultry so we can utilize this function inside of a graph. After visualizing a smooth graph we can see the peak price for cheap products under $3 was in 2009. In the expenisive poultry we notice a major dip in prices in 2008 when there was a crash.

Poultry %>%
  filter(Price_Dollar < 3) %>%
  arrange(desc(Year, Price_Dollar)) -> Cheap_poultry

ggplot(data = Cheap_poultry) +
  geom_smooth(mapping = aes(x = Year, y = Price_Dollar), se = FALSE)
Poultry %>%
  filter(Price_Dollar > 3) %>%
  arrange(desc(Year, Price_Dollar)) -> expensive_poultry


ggplot(data = expensive_poultry) +
  geom_smooth(mapping = aes(x = Year, y = Price_Dollar), se = FALSE)

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

campbell (2022, Feb. 9). Data Analytics and Computational Social Science: Ethan Campbell HW2. Retrieved from https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomethancampbell864073/

BibTeX citation

@misc{campbell2022ethan,
  author = {campbell, Ethan},
  title = {Data Analytics and Computational Social Science: Ethan Campbell HW2},
  url = {https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomethancampbell864073/},
  year = {2022}
}