Unnest a ts class











up vote
0
down vote

favorite












My data has multiple customers data with different start and end dates along with their sales data.So I did simple exponential smoothing.
My data set :



structure(list(customer_id = c("1-FI", "1-FI", "1-FI", "1-FI", 
"1-FI", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188"), sales = c(100.9418694, 121.80921729,
131.13242701, 129.25146751, 130.9114891, 59.862175475, 26.242577152,
26.242583584, 26.242582726, 26.242605024, 26.243207488, 26.244399981,
26.24368903, 26.242590016, 26.242607168, 26.244073664, 26.242733235,
26.252639373, 382.25686237, 383.5729855, 395.04823051, 410.71253335,
380.97085, 415.60929042, 405.40406353, 389.73811453, 422.75106934,
424.95123013, 396.27195067, 397.22035121, 403.07871072, 390.51585696,
387.14589889, 356.47379073, 409.86190435, 362.1045076, 482.70803877,
401.04191501, 396.80578737, 182.69071425, 182.90770549, 156.78630936,
162.01545504, 154.59593421, 149.63253734, 183.18470086, 196.32791655,
183.93584654, 186.03057785, 186.22590654, 156.09019587, 137.76343138,
127.0869966, 137.34694566, 133.25311402, 122.55553768, 118.22456292,
159.65747998, 122.77510258, 157.04492207, 35.161096589, 45.037465606,
37.637919142, 35.049382182, 32.801385318, 39.203592294, 37.741972608,
38.730897325, 72.049982746, 40.391500365, 41.502300762, 38.760239251,
40.77839417, 36.989308973, 40.167455795, 33.865745389, 43.924857389,
39.943200256, 38.908906355, 32.228421472, 40.341142093, 47.464460314,
50.49858951, 57.964360275, 50.21179049, 60.817118221, 54.677239507,
53.517382246, 51.296274573, 89.214368205, 51.205341958, 45.581040358,
48.318404365, 56.420713722, 50.733345075, 47.746574266, 51.449188512,
53.159378413, 51.672878035, 54.984310906, 49.853546957, 54.635080749,
33.869158637, 36.420494624, 34.201671168, 31.169316346, 31.453926771,
30.995599174, 34.941078022, 36.430641747, 72.9296608, 44.5318984,
51.272563219, 40.981600774, 41.276944922, 34.307531597, 34.856211642,
35.116862867, 53.886082496, 32.843276934, 67.787450893, 64.072083277,
67.164756966, 37.15244679, 41.802139162, 45.057952384, 41.183183085,
40.94067696, 44.759495578, 45.310676813, 42.227278496, 77.741274912,
45.850713107, 37.290041421, 39.694496685, 43.410913574, 35.870854496,
39.492859059, 39.508746528, 35.526071853, 30.332660653, 30.208349818,
30.188126323, 33.049433254), Date = structure(c(17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727), class = "Date")), row.names = c(NA,
144L), class = "data.frame")


and I applied the following code to apply ses



library(zoo)
library(forecast)

z <- read.zoo(data_set,FUN = function(x) as.Date(x) + seq_along(x) / 10^10 , index = "Date", split = "customer_id")
L <- lapply(as.list(z), function(x) ts(na.omit(x),frequency = 52))
HW <- lapply(L, ses)


Now my output class is list with uneven lengths.Can someone help me how to unnest or unlist the output in to a data frame and get the fitted values,actuals,residuals along with their dates,sales and customer_id.
Note : the reson I post my input data rather than data of HW is,the HW data is too large.
Can someone help me in R.










share|improve this question
























  • Please be clear, are you using forecast::ses?
    – r2evans
    Nov 19 at 15:58






  • 1




    Yes@r2evans and edited my question.Thanks!
    – riyan
    Nov 19 at 16:00










  • @G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
    – riyan
    Nov 19 at 17:30










  • In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
    – Giorgi Chighladze
    Nov 19 at 21:40

















up vote
0
down vote

favorite












My data has multiple customers data with different start and end dates along with their sales data.So I did simple exponential smoothing.
My data set :



structure(list(customer_id = c("1-FI", "1-FI", "1-FI", "1-FI", 
"1-FI", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188"), sales = c(100.9418694, 121.80921729,
131.13242701, 129.25146751, 130.9114891, 59.862175475, 26.242577152,
26.242583584, 26.242582726, 26.242605024, 26.243207488, 26.244399981,
26.24368903, 26.242590016, 26.242607168, 26.244073664, 26.242733235,
26.252639373, 382.25686237, 383.5729855, 395.04823051, 410.71253335,
380.97085, 415.60929042, 405.40406353, 389.73811453, 422.75106934,
424.95123013, 396.27195067, 397.22035121, 403.07871072, 390.51585696,
387.14589889, 356.47379073, 409.86190435, 362.1045076, 482.70803877,
401.04191501, 396.80578737, 182.69071425, 182.90770549, 156.78630936,
162.01545504, 154.59593421, 149.63253734, 183.18470086, 196.32791655,
183.93584654, 186.03057785, 186.22590654, 156.09019587, 137.76343138,
127.0869966, 137.34694566, 133.25311402, 122.55553768, 118.22456292,
159.65747998, 122.77510258, 157.04492207, 35.161096589, 45.037465606,
37.637919142, 35.049382182, 32.801385318, 39.203592294, 37.741972608,
38.730897325, 72.049982746, 40.391500365, 41.502300762, 38.760239251,
40.77839417, 36.989308973, 40.167455795, 33.865745389, 43.924857389,
39.943200256, 38.908906355, 32.228421472, 40.341142093, 47.464460314,
50.49858951, 57.964360275, 50.21179049, 60.817118221, 54.677239507,
53.517382246, 51.296274573, 89.214368205, 51.205341958, 45.581040358,
48.318404365, 56.420713722, 50.733345075, 47.746574266, 51.449188512,
53.159378413, 51.672878035, 54.984310906, 49.853546957, 54.635080749,
33.869158637, 36.420494624, 34.201671168, 31.169316346, 31.453926771,
30.995599174, 34.941078022, 36.430641747, 72.9296608, 44.5318984,
51.272563219, 40.981600774, 41.276944922, 34.307531597, 34.856211642,
35.116862867, 53.886082496, 32.843276934, 67.787450893, 64.072083277,
67.164756966, 37.15244679, 41.802139162, 45.057952384, 41.183183085,
40.94067696, 44.759495578, 45.310676813, 42.227278496, 77.741274912,
45.850713107, 37.290041421, 39.694496685, 43.410913574, 35.870854496,
39.492859059, 39.508746528, 35.526071853, 30.332660653, 30.208349818,
30.188126323, 33.049433254), Date = structure(c(17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727), class = "Date")), row.names = c(NA,
144L), class = "data.frame")


and I applied the following code to apply ses



library(zoo)
library(forecast)

z <- read.zoo(data_set,FUN = function(x) as.Date(x) + seq_along(x) / 10^10 , index = "Date", split = "customer_id")
L <- lapply(as.list(z), function(x) ts(na.omit(x),frequency = 52))
HW <- lapply(L, ses)


Now my output class is list with uneven lengths.Can someone help me how to unnest or unlist the output in to a data frame and get the fitted values,actuals,residuals along with their dates,sales and customer_id.
Note : the reson I post my input data rather than data of HW is,the HW data is too large.
Can someone help me in R.










share|improve this question
























  • Please be clear, are you using forecast::ses?
    – r2evans
    Nov 19 at 15:58






  • 1




    Yes@r2evans and edited my question.Thanks!
    – riyan
    Nov 19 at 16:00










  • @G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
    – riyan
    Nov 19 at 17:30










  • In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
    – Giorgi Chighladze
    Nov 19 at 21:40















up vote
0
down vote

favorite









up vote
0
down vote

favorite











My data has multiple customers data with different start and end dates along with their sales data.So I did simple exponential smoothing.
My data set :



structure(list(customer_id = c("1-FI", "1-FI", "1-FI", "1-FI", 
"1-FI", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188"), sales = c(100.9418694, 121.80921729,
131.13242701, 129.25146751, 130.9114891, 59.862175475, 26.242577152,
26.242583584, 26.242582726, 26.242605024, 26.243207488, 26.244399981,
26.24368903, 26.242590016, 26.242607168, 26.244073664, 26.242733235,
26.252639373, 382.25686237, 383.5729855, 395.04823051, 410.71253335,
380.97085, 415.60929042, 405.40406353, 389.73811453, 422.75106934,
424.95123013, 396.27195067, 397.22035121, 403.07871072, 390.51585696,
387.14589889, 356.47379073, 409.86190435, 362.1045076, 482.70803877,
401.04191501, 396.80578737, 182.69071425, 182.90770549, 156.78630936,
162.01545504, 154.59593421, 149.63253734, 183.18470086, 196.32791655,
183.93584654, 186.03057785, 186.22590654, 156.09019587, 137.76343138,
127.0869966, 137.34694566, 133.25311402, 122.55553768, 118.22456292,
159.65747998, 122.77510258, 157.04492207, 35.161096589, 45.037465606,
37.637919142, 35.049382182, 32.801385318, 39.203592294, 37.741972608,
38.730897325, 72.049982746, 40.391500365, 41.502300762, 38.760239251,
40.77839417, 36.989308973, 40.167455795, 33.865745389, 43.924857389,
39.943200256, 38.908906355, 32.228421472, 40.341142093, 47.464460314,
50.49858951, 57.964360275, 50.21179049, 60.817118221, 54.677239507,
53.517382246, 51.296274573, 89.214368205, 51.205341958, 45.581040358,
48.318404365, 56.420713722, 50.733345075, 47.746574266, 51.449188512,
53.159378413, 51.672878035, 54.984310906, 49.853546957, 54.635080749,
33.869158637, 36.420494624, 34.201671168, 31.169316346, 31.453926771,
30.995599174, 34.941078022, 36.430641747, 72.9296608, 44.5318984,
51.272563219, 40.981600774, 41.276944922, 34.307531597, 34.856211642,
35.116862867, 53.886082496, 32.843276934, 67.787450893, 64.072083277,
67.164756966, 37.15244679, 41.802139162, 45.057952384, 41.183183085,
40.94067696, 44.759495578, 45.310676813, 42.227278496, 77.741274912,
45.850713107, 37.290041421, 39.694496685, 43.410913574, 35.870854496,
39.492859059, 39.508746528, 35.526071853, 30.332660653, 30.208349818,
30.188126323, 33.049433254), Date = structure(c(17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727), class = "Date")), row.names = c(NA,
144L), class = "data.frame")


and I applied the following code to apply ses



library(zoo)
library(forecast)

z <- read.zoo(data_set,FUN = function(x) as.Date(x) + seq_along(x) / 10^10 , index = "Date", split = "customer_id")
L <- lapply(as.list(z), function(x) ts(na.omit(x),frequency = 52))
HW <- lapply(L, ses)


Now my output class is list with uneven lengths.Can someone help me how to unnest or unlist the output in to a data frame and get the fitted values,actuals,residuals along with their dates,sales and customer_id.
Note : the reson I post my input data rather than data of HW is,the HW data is too large.
Can someone help me in R.










share|improve this question















My data has multiple customers data with different start and end dates along with their sales data.So I did simple exponential smoothing.
My data set :



structure(list(customer_id = c("1-FI", "1-FI", "1-FI", "1-FI", 
"1-FI", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175", "1-G0175",
"1-G0175", "1-G0175", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182",
"1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0182", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183", "1-H0183",
"1-H0183", "1-H0183", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184",
"1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0184", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185", "1-H0185",
"1-H0185", "1-H0185", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186",
"1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0186", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188", "1-H0188",
"1-H0188", "1-H0188"), sales = c(100.9418694, 121.80921729,
131.13242701, 129.25146751, 130.9114891, 59.862175475, 26.242577152,
26.242583584, 26.242582726, 26.242605024, 26.243207488, 26.244399981,
26.24368903, 26.242590016, 26.242607168, 26.244073664, 26.242733235,
26.252639373, 382.25686237, 383.5729855, 395.04823051, 410.71253335,
380.97085, 415.60929042, 405.40406353, 389.73811453, 422.75106934,
424.95123013, 396.27195067, 397.22035121, 403.07871072, 390.51585696,
387.14589889, 356.47379073, 409.86190435, 362.1045076, 482.70803877,
401.04191501, 396.80578737, 182.69071425, 182.90770549, 156.78630936,
162.01545504, 154.59593421, 149.63253734, 183.18470086, 196.32791655,
183.93584654, 186.03057785, 186.22590654, 156.09019587, 137.76343138,
127.0869966, 137.34694566, 133.25311402, 122.55553768, 118.22456292,
159.65747998, 122.77510258, 157.04492207, 35.161096589, 45.037465606,
37.637919142, 35.049382182, 32.801385318, 39.203592294, 37.741972608,
38.730897325, 72.049982746, 40.391500365, 41.502300762, 38.760239251,
40.77839417, 36.989308973, 40.167455795, 33.865745389, 43.924857389,
39.943200256, 38.908906355, 32.228421472, 40.341142093, 47.464460314,
50.49858951, 57.964360275, 50.21179049, 60.817118221, 54.677239507,
53.517382246, 51.296274573, 89.214368205, 51.205341958, 45.581040358,
48.318404365, 56.420713722, 50.733345075, 47.746574266, 51.449188512,
53.159378413, 51.672878035, 54.984310906, 49.853546957, 54.635080749,
33.869158637, 36.420494624, 34.201671168, 31.169316346, 31.453926771,
30.995599174, 34.941078022, 36.430641747, 72.9296608, 44.5318984,
51.272563219, 40.981600774, 41.276944922, 34.307531597, 34.856211642,
35.116862867, 53.886082496, 32.843276934, 67.787450893, 64.072083277,
67.164756966, 37.15244679, 41.802139162, 45.057952384, 41.183183085,
40.94067696, 44.759495578, 45.310676813, 42.227278496, 77.741274912,
45.850713107, 37.290041421, 39.694496685, 43.410913574, 35.870854496,
39.492859059, 39.508746528, 35.526071853, 30.332660653, 30.208349818,
30.188126323, 33.049433254), Date = structure(c(17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727, 17587, 17594, 17601,
17608, 17615, 17622, 17629, 17636, 17643, 17650, 17657, 17664,
17671, 17678, 17685, 17692, 17699, 17706, 17713, 17720, 17727,
17587, 17594, 17601, 17608, 17615, 17622, 17629, 17636, 17643,
17650, 17657, 17664, 17671, 17678, 17685, 17692, 17699, 17706,
17713, 17720, 17727, 17587, 17594, 17601, 17608, 17615, 17622,
17629, 17636, 17643, 17650, 17657, 17664, 17671, 17678, 17685,
17692, 17699, 17706, 17713, 17720, 17727), class = "Date")), row.names = c(NA,
144L), class = "data.frame")


and I applied the following code to apply ses



library(zoo)
library(forecast)

z <- read.zoo(data_set,FUN = function(x) as.Date(x) + seq_along(x) / 10^10 , index = "Date", split = "customer_id")
L <- lapply(as.list(z), function(x) ts(na.omit(x),frequency = 52))
HW <- lapply(L, ses)


Now my output class is list with uneven lengths.Can someone help me how to unnest or unlist the output in to a data frame and get the fitted values,actuals,residuals along with their dates,sales and customer_id.
Note : the reson I post my input data rather than data of HW is,the HW data is too large.
Can someone help me in R.







r dataframe time-series exponential unnest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 16:00

























asked Nov 19 at 15:52









riyan

106




106












  • Please be clear, are you using forecast::ses?
    – r2evans
    Nov 19 at 15:58






  • 1




    Yes@r2evans and edited my question.Thanks!
    – riyan
    Nov 19 at 16:00










  • @G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
    – riyan
    Nov 19 at 17:30










  • In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
    – Giorgi Chighladze
    Nov 19 at 21:40




















  • Please be clear, are you using forecast::ses?
    – r2evans
    Nov 19 at 15:58






  • 1




    Yes@r2evans and edited my question.Thanks!
    – riyan
    Nov 19 at 16:00










  • @G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
    – riyan
    Nov 19 at 17:30










  • In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
    – Giorgi Chighladze
    Nov 19 at 21:40


















Please be clear, are you using forecast::ses?
– r2evans
Nov 19 at 15:58




Please be clear, are you using forecast::ses?
– r2evans
Nov 19 at 15:58




1




1




Yes@r2evans and edited my question.Thanks!
– riyan
Nov 19 at 16:00




Yes@r2evans and edited my question.Thanks!
– riyan
Nov 19 at 16:00












@G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
– riyan
Nov 19 at 17:30




@G.Grothendieck I tried your method but it showed me like columns names like Point Forecast , Lo 80, Hi 80 basically it showed me the intervals other than the fitted values and actual values which we can see in dput(HW) or view of HW.
– riyan
Nov 19 at 17:30












In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
– Giorgi Chighladze
Nov 19 at 21:40






In order to unlist your output, you need to convert each element from class forecast to data.frame, and then you can bind the list elements together using bind_rows from package dplyr
– Giorgi Chighladze
Nov 19 at 21:40














1 Answer
1






active

oldest

votes

















up vote
1
down vote













I would use tidyverse package to handle this problem.



map(HW, ~ .x %>% 
as.data.frame %>% # convert each element of the list to data.frame
rownames_to_column) %>% # add row names as columns within each element
bind_rows(.id = "customer_id") # bind all elements and add customer ID


I am not sure how to relate dates and actual sales to your output (HW). If you explain it I might provide solution to that part of the problem too.






share|improve this answer





















  • Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
    – riyan
    yesterday










  • @riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
    – Giorgi Chighladze
    8 hours ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378287%2funnest-a-ts-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













I would use tidyverse package to handle this problem.



map(HW, ~ .x %>% 
as.data.frame %>% # convert each element of the list to data.frame
rownames_to_column) %>% # add row names as columns within each element
bind_rows(.id = "customer_id") # bind all elements and add customer ID


I am not sure how to relate dates and actual sales to your output (HW). If you explain it I might provide solution to that part of the problem too.






share|improve this answer





















  • Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
    – riyan
    yesterday










  • @riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
    – Giorgi Chighladze
    8 hours ago















up vote
1
down vote













I would use tidyverse package to handle this problem.



map(HW, ~ .x %>% 
as.data.frame %>% # convert each element of the list to data.frame
rownames_to_column) %>% # add row names as columns within each element
bind_rows(.id = "customer_id") # bind all elements and add customer ID


I am not sure how to relate dates and actual sales to your output (HW). If you explain it I might provide solution to that part of the problem too.






share|improve this answer





















  • Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
    – riyan
    yesterday










  • @riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
    – Giorgi Chighladze
    8 hours ago













up vote
1
down vote










up vote
1
down vote









I would use tidyverse package to handle this problem.



map(HW, ~ .x %>% 
as.data.frame %>% # convert each element of the list to data.frame
rownames_to_column) %>% # add row names as columns within each element
bind_rows(.id = "customer_id") # bind all elements and add customer ID


I am not sure how to relate dates and actual sales to your output (HW). If you explain it I might provide solution to that part of the problem too.






share|improve this answer












I would use tidyverse package to handle this problem.



map(HW, ~ .x %>% 
as.data.frame %>% # convert each element of the list to data.frame
rownames_to_column) %>% # add row names as columns within each element
bind_rows(.id = "customer_id") # bind all elements and add customer ID


I am not sure how to relate dates and actual sales to your output (HW). If you explain it I might provide solution to that part of the problem too.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 22:10









Giorgi Chighladze

665




665












  • Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
    – riyan
    yesterday










  • @riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
    – Giorgi Chighladze
    8 hours ago


















  • Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
    – riyan
    yesterday










  • @riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
    – Giorgi Chighladze
    8 hours ago
















Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
– riyan
yesterday




Still no luck,the output is showing only Lo and Hi values.I just want the actual values(from input),dates(from input) alsong with their customer_id and their exponential values in a data frame.
– riyan
yesterday












@riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
– Giorgi Chighladze
8 hours ago




@riyan, can you show what the final table should look like. For instance, for customer "I-H0188" how do you want to combine HW and input data.
– Giorgi Chighladze
8 hours ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378287%2funnest-a-ts-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen