HW2 Submission
Load Libraries need for this routine
##Read Read in a clean data set
egg <- read_excel("_data/eggs_tidy.xlsx")
head(egg)
# A tibble: 6 x 6
month year large_half_dozen large_dozen extra_large_half_dozen
<chr> <dbl> <dbl> <dbl> <dbl>
1 January 2004 126 230 132
2 February 2004 128. 226. 134.
3 March 2004 131 225 137
4 April 2004 131 225 137
5 May 2004 131 225 137
6 June 2004 134. 231. 137
# ... with 1 more variable: extra_large_dozen <dbl>
# A tibble: 6 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
##Transform Working with eggs: -pivot the data so size, qtry is a variable not seperatet columns -create a new data set with filter -modify to add seperate columns for size and Qty -TO DO: change the values in the size and Qty columns but I don’t know how to do this yet.
#head(egg)
#select(egg,"month","year":"extra_large_dozen")
egg_long <- pivot_longer(egg, "large_half_dozen":"extra_large_dozen")
egg_lg_dz <- filter(egg_long, name=="large_dozen")
egg_long <- rename(egg_long, "size" = name)
egg_long <- mutate(egg_long, "Qty" = size)
head(egg_long)
# A tibble: 6 x 5
month year size value Qty
<chr> <dbl> <chr> <dbl> <chr>
1 January 2004 large_half_dozen 126 large_half_dozen
2 January 2004 large_dozen 230 large_dozen
3 January 2004 extra_large_half_dozen 132 extra_large_half_dozen
4 January 2004 extra_large_dozen 230 extra_large_dozen
5 February 2004 large_half_dozen 128. large_half_dozen
6 February 2004 large_dozen 226. large_dozen
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
O'Connell (2022, Feb. 20). Data Analytics and Computational Social Science: HW2 - Submission 2. Retrieved from https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomnorthonum867107/
BibTeX citation
@misc{o'connell2022hw2, author = {O'Connell, Jason}, title = {Data Analytics and Computational Social Science: HW2 - Submission 2}, url = {https://github.com/DACSS/dacss_course_website/posts/httpsrpubscomnorthonum867107/}, year = {2022} }