0

I have the following data:

df=data.frame(store=c('A','A','A','A','B','B','B','B'),
              Date=c('2017-01-01','2017-01-02','2017-01-03','2017-01-04','2017-01-01','2017-01-02','2017-01-03','2017-01-04'),
              sales=c('15','37','29','18','16','22','5','6'))
   
df 

store       Date sales
1     A 2017-01-01    15
2     A 2017-01-02    37
3     A 2017-01-03    29
4     A 2017-01-04    18
5     B 2017-01-01    16
6     B 2017-01-02    22
7     B 2017-01-03     5
8     B 2017-01-04     6

I would like to convert it into a time series format as below:

        Date  A  B
1 2017-01-01 15 16
2 2017-01-02 37 22
3 2017-01-03 29  5
4 2017-01-04 18  6

I need to run auto.arima(from forecast package) iteratively on time series A & B.Hence i require the data frame to be the ts format.

Nishant
  • 1,063
  • 13
  • 40
  • 1
    you could look into `reshape(df, idvar = "Date", dir="wide", timevar = "store")` reshape, spread, pivot_wider etc – Onyambu Sep 17 '20 at 05:40
  • you can use tidyr package `wide_data <- tidyr::pivot_wider(df, names_from = store, values_from = sales)` – Econ_matrix Oct 07 '20 at 09:09

0 Answers0