I have a large data set, and I'm trying to create a table that shows the number of observations in each zip code for each year. The tricky part is I need each column to be a year, and the rows to be the number of observations of each zip code in each year. Some zip codes have no observations in one of the years, so there should be some empty slots. I only know how to create three separate tables with the three separate years, which is what the code is for below. Could someone help me basically combine this into one table?
BuildingZipCodes18 <- Data %>% filter(year(`Issued Date`) == 2018) %>% group_by(`Zip`) %>% summarise("2018" = n()) BuildingZipCodes19 <- Data %>% filter(year(`Issued Date`) == 2019) %>% group_by(`Zip`) %>% summarise("2019" = n()) BuildingZipCodes20 <- Data %>% filter(year(`Issued Date`) == 2020) %>% group_by(`Zip`) %>% summarise("2020" = n())
https://stackoverflow.com/questions/65801864/combining-tables-in-dplyr January 20, 2021 at 09:26AM
没有评论:
发表评论