Time series data represented in columns

Hi All,

It would be great if someone can help on how to run a time series model when a data is present in columns
Eg:
Col1 - Col 2 Col 3 Col 4
Time series name Date1 Date 2 Date 3 etc..

I have the data in columns in a monthly buckets. Also i have a total of 100+ time series and it's not easy to convert it to rows representation. Can someone advice on how to run a univariate models when a data is in this order?
Can i run all the 100+ time series in R?

Could I ask you to edit your question to give a more clear idea of the format that your data is in? I'm not sure what the data is like from your description.

Is the time series progressing from left to right or top to bottom?

Hello, to make it clear the data is from left to right. Like 1,2,3,4,5,6,7,8,9 etc

Sorry for my poor explanation

Rotating the data to be in columns from top to bottom can be done like this.

``````library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#>     date
library(tidyr)
df <- data.frame(Name = c("A", "B", "C", "D"),
Date1 = c(1,2,3,4),
Date2 = c(11,12,13,14),
Date3 = c(21,22,23,24),
Date4 = c(31,32,33,34))
df
#>   Name Date1 Date2 Date3 Date4
#> 1    A     1    11    21    31
#> 2    B     2    12    22    32
#> 3    C     3    13    23    33
#> 4    D     4    14    24    34
df2 <- df %>% gather(key = "DATE", value = "Value", Date1:Date4)
df2
#>    Name  DATE Value
#> 1     A Date1     1
#> 2     B Date1     2
#> 3     C Date1     3
#> 4     D Date1     4
#> 5     A Date2    11
#> 6     B Date2    12
#> 7     C Date2    13
#> 8     D Date2    14
#> 9     A Date3    21
#> 10    B Date3    22
#> 11    C Date3    23
#> 12    D Date3    24
#> 13    A Date4    31
#> 14    B Date4    32
#> 15    C Date4    33
#> 16    D Date4    34
df3 <- df2 %>% spread(key = "Name", value = "Value")
df3
#>    DATE  A  B  C  D
#> 1 Date1  1  2  3  4
#> 2 Date2 11 12 13 14
#> 3 Date3 21 22 23 24
#> 4 Date4 31 32 33 34
``````

Created on 2019-05-06 by the reprex package (v0.2.1)
You can then process the data easily with map() from the purrr package

Thank you! However as mentioned there are more than 100+ time series and I need to work on best univariate forecasting model on each and every one of them. Is there a way where I can do it?

You can use purrr::map() or lapply() to apply a function to each column of a data frame. If you had only a single column to work with, what would you do? If you explain that, someone can probably help you apply it to every column (or row).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.