DACSS-601
library(readxl)
library(dplyr)
poultry_tidy<- read_excel(path="/Users/katpo/Documents/R/poultry_tidy.xlsx")
poultry_tidy
# A tibble: 600 x 4
Product Year Month Price_Dollar
<chr> <dbl> <chr> <dbl>
1 Whole 2013 January 2.38
2 Whole 2013 February 2.38
3 Whole 2013 March 2.38
4 Whole 2013 April 2.38
5 Whole 2013 May 2.38
6 Whole 2013 June 2.38
7 Whole 2013 July 2.38
8 Whole 2013 August 2.38
9 Whole 2013 September 2.38
10 Whole 2013 October 2.38
# ... with 590 more rows
colnames(poultry_tidy)
[1] "Product" "Year" "Month" "Price_Dollar"
The column names refer to the type of poultry product (breast, thighs, whole bird, etc.), the year and month it was produced and the price. With all of these elements together, this data set tracks the price of poultry over a set period of time.
#Dimensions of the data set
dim(poultry_tidy)
[1] 600 4
I’m going to filter the data by Product (I chose whole legs)
poultry_legs<-filter(poultry_tidy, Product == "Whole Legs")
Next I’ll arrange the filtered data set by year
# A tibble: 120 x 4
Product Year Month Price_Dollar
<chr> <dbl> <chr> <dbl>
1 Whole Legs 2013 January 2.04
2 Whole Legs 2013 February 2.04
3 Whole Legs 2013 March 2.04
4 Whole Legs 2013 April 2.04
5 Whole Legs 2013 May 2.04
6 Whole Legs 2013 June 2.04
7 Whole Legs 2013 July 2.04
8 Whole Legs 2013 August 2.04
9 Whole Legs 2013 September 2.04
10 Whole Legs 2013 October 2.04
# ... with 110 more rows
The filtered data still presents a broad range of information, so I’m going arrange the data by price (least to most expensive)
poultry_arranged %>%
select(Year, Price_Dollar) %>%
group_by(Year) %>%
arrange(desc(Price_Dollar)) %>%
slice(10)
# A tibble: 10 x 2
# Groups: Year [10]
Year Price_Dollar
<dbl> <dbl>
1 2004 1.94
2 2005 2.04
3 2006 2.04
4 2007 2.04
5 2008 2.04
6 2009 2.04
7 2010 2.04
8 2011 2.04
9 2012 2.04
10 2013 2.04
The price of whole chicken legs remained, for the most part, stagnant (other than 2004-2005 when the price went from $1.94 to $2.04)
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 ...".
For attribution, please cite this work as
Popiela (2022, March 23). Data Analytics and Computational Social Science: Homework 2. Retrieved from https://github.com/DACSS/dacss_course_website/posts/httprpubscomkpopiela879207/
BibTeX citation
@misc{popiela2022homework, author = {Popiela, Katie}, title = {Data Analytics and Computational Social Science: Homework 2}, url = {https://github.com/DACSS/dacss_course_website/posts/httprpubscomkpopiela879207/}, year = {2022} }