My data frame is SPData, which includes date, open price, closing price and volume for the S&P500 for the last 25 years (~ 250 days per year).
Additionally, I have SPData$Year
, which is simply a vector with the year from the date column stored numerically, from 1990 - 2015.
library(dplyr)
SPData1990 <- filter(SPData, Year == 1990)
results in a data frame with ~250 observations, one for each trading day in 1990. I did this for all 25 years already.
Is there a way to create a formula that would save all the other data corresponding from each year as a new data frame (SPData1991, SPData 1992, SPData1993, etc.)? I was trying to think through a for(i in years) loop corresponding to the formula, years <- unique(SPData$Year, FALSE)
, but I am not familiar enough with programming in general to figure this out.
Thanks