I have a dataset of names and values, e.g.
Date Name Value
01/01/17 Miles ran 1.2
02/01/17 Miles ran 1.2
03/01/17 Miles ran 1.3
04/01/17 Miles ran 1.4
05/01/17 Miles ran 1.4
06/01/17 Miles ran 1.6
07/01/17 Miles ran 1.5
08/01/17 Miles ran 1.8
09/01/17 Miles ran 1.7
10/01/17 Miles ran 2.1
01/01/17 Calories consumed 2300
02/01/17 Calories consumed 2200
03/01/17 Calories consumed 2250
04/01/17 Calories consumed 2410
05/01/17 Calories consumed 1980
06/01/17 Calories consumed 2000
07/01/17 Calories consumed 1900
08/01/17 Calories consumed 2400
09/01/17 Calories consumed 2150
10/01/17 Calories consumed 1900
I want to be able to run various calculations on the data, such as being able to run a forecast() function on the data for each separate time series in the panel data (dates already defined).
However, I am unsure as to how to loop using subset. e.g. I have to define the name reference for the subset each time, and would rather achieve this by means of a loop which runs the calculation on each subset in turn.
This is my current code:
listofids=as.character(unique(mydata$Name))
mylist1 <- split(mydata, mydata$Name)
mylist1
df1<-data.frame(mylist[1])
listofids=as.character(unique(mydata$Name))
mylist2 <- split(mydata, mydata$Name)
mylist2
df2<-data.frame(mylist[2])
forecast(df1$Value,h=365-Number_of_Days)
The idea is to segment the panel data into separate datasets, and then conduct the forecasts. However, as can be seen above, I would need to run separate forecasts for each separate data frame and want to loop this instead. Any help would be greatly appreciated.