0

I have a data frame with the following column names.

"week" "demand" "product-id"

The problem is to convert it into a time series object.

week is a number like 3,4,5,6,7,8,9 etc., and demand is in units and product-id is unique.

I want to convert the week column into time series, so as to prepare for modeling.

I want to predict weeks 10 and 11 demand by using an ARIMA model. How do I do that?

Hack-R
  • 22,422
  • 14
  • 75
  • 131
  • 1
    Welcome to StackOverflow! Please provide a MCVE with questions regarding how to write code http://stackoverflow.com/help/mcve and please take care to use proper capitalization, grammar, and formatting in your questions. I've made some improvements to the question but please provide sample data and code to represent what you've done thusfar. – Hack-R Jul 13 '16 at 12:52

1 Answers1

1
myTS <- ts(mydataframe[-1], frequency = 52)

will convert your demand and productId to a timeseries of 52 observations per year. For more elaborate timeseries, check package xts. Also compare this post on weekly data with ts.

Community
  • 1
  • 1
sebastianmm
  • 1,148
  • 1
  • 8
  • 26
  • Thank you for replying promptly. what do i do if i have some missing weeks.ie., @week is 3,6,7,8 etc .. with missing values – Bindukumar Jampana Jul 14 '16 at 12:47
  • That depends on what you want the values to be: NA? An interpolation of neighboring values? Last observation carried forward? One way would be to create a list of `week` values, like so: `wks <- rep(seq(1, 52), numberOfYears)`, then [`dplyr::left_join(wks, mydataframe)`](https://cran.r-project.org/web/packages/dplyr/vignettes/two-table.html) to create a list including missing weeks. Then choose some function like [`zoo::na.locf`](http://search.r-project.org/library/zoo/html/na.locf.html) to fill the missing values. – sebastianmm Jul 14 '16 at 13:16
  • are you sure that mydataframe[-1] will do the work for me i am expecting that the column with week should be fed to ts() function. as there are three columns as stated in the above problem. – Bindukumar Jampana Jul 15 '16 at 13:12
  • Well, have you tried it? Do you know what it does and how to call ts()? – sebastianmm Jul 15 '16 at 13:16
  • i donot know how ts() function works , i would really appreciate any direction you provide in understanding time series and `ts()` function – Bindukumar Jampana Jul 20 '16 at 11:44