I am trying to use a for loop to filter a large dataset by year. I then want to create new datasets in the global environment that I can use for further calculations.
creating list of years
years <- c("2006", "2007", "2008", "2009", "2010", "2011", "2012")
for loop
for (i in years) {
pill_[[i]] <- tract_pills %>%
filter(year == i)
print(paste0("Finish ", i)
}
I can get this to work, but it doesn't create the datasets for each year. It only create the dataset for the last year.