Convert multiple ID's weekly data to time series format
Here is the structure of my data
structure(list(customer_id = c("A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B"), state = c("NC", "NC", "NC",
"NC", "NC", "NC", "NC", "NC", "KA", "KA", "KA", "KA", "KA"),
value = c(20.4, 29, 26, 40, 35, 36, 28, 41, 70, 75, 78, 99,
40), Date = structure(c(17784, 17791, 17798, 17805, 17812,
17819, 17826, 17833, 17608, 17615, 17622, 17629, 17636), class = "Date")), row.names = c(NA,
-13L), class = "data.frame")
I have so many customers of data from different state with different start and end dates.
I'd like to convert this data to time_series data and perform exponential smoothing using hw
method.
The code which I have tried to convert to time_series is:
temp <- multiple_ts %>%
group_by(state,customer_id) %>%
ts(multiple_ts$value, frequency = 52)
I used frequency as 52 because the data is weekly_data,but the code is throwing an error
Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
my output_data is
structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20.4, 29,
26, 40, 35, 36, 28, 41, 70, 75, 78, 99, 40, 17784, 17791, 17798,
17805, 17812, 17819, 17826, 17833, 17608, 17615, 17622, 17629,
17636), .Dim = c(13L, 4L), .Dimnames = list(NULL, c("customer_id",
"state", "value", "Date")), .Tsp = c(20.9384615384615, 21.1692307692308,
52), class = c("mts", "ts", "matrix"))
Can someone help me in R.
Thanks in Advance
r dplyr time-series smoothing exponential
|
show 3 more comments
Here is the structure of my data
structure(list(customer_id = c("A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B"), state = c("NC", "NC", "NC",
"NC", "NC", "NC", "NC", "NC", "KA", "KA", "KA", "KA", "KA"),
value = c(20.4, 29, 26, 40, 35, 36, 28, 41, 70, 75, 78, 99,
40), Date = structure(c(17784, 17791, 17798, 17805, 17812,
17819, 17826, 17833, 17608, 17615, 17622, 17629, 17636), class = "Date")), row.names = c(NA,
-13L), class = "data.frame")
I have so many customers of data from different state with different start and end dates.
I'd like to convert this data to time_series data and perform exponential smoothing using hw
method.
The code which I have tried to convert to time_series is:
temp <- multiple_ts %>%
group_by(state,customer_id) %>%
ts(multiple_ts$value, frequency = 52)
I used frequency as 52 because the data is weekly_data,but the code is throwing an error
Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
my output_data is
structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20.4, 29,
26, 40, 35, 36, 28, 41, 70, 75, 78, 99, 40, 17784, 17791, 17798,
17805, 17812, 17819, 17826, 17833, 17608, 17615, 17622, 17629,
17636), .Dim = c(13L, 4L), .Dimnames = list(NULL, c("customer_id",
"state", "value", "Date")), .Tsp = c(20.9384615384615, 21.1692307692308,
52), class = c("mts", "ts", "matrix"))
Can someone help me in R.
Thanks in Advance
r dplyr time-series smoothing exponential
1
Those aren't errors, they're warnings. There might be nothing wrong except you haveNA
values.
– thelatemail
Nov 12 '18 at 2:52
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
Trying to combinets
anddplyr
'sgroup_by
doesn't seem to work. You end up with a malformedmatrix
. As per this question, you might be better using thexts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping -lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing usinghw
method it showed me asError in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail
– Lalitha
Nov 12 '18 at 3:59
I'm not sure how you ended up with a multiple time series. The code I pasted abovesplit
smultiple_ts$value
, which results in the required "univariate time series". Did you split the wholemultiple_ts
ormultiple_ts$value
?
– thelatemail
Nov 12 '18 at 4:11
|
show 3 more comments
Here is the structure of my data
structure(list(customer_id = c("A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B"), state = c("NC", "NC", "NC",
"NC", "NC", "NC", "NC", "NC", "KA", "KA", "KA", "KA", "KA"),
value = c(20.4, 29, 26, 40, 35, 36, 28, 41, 70, 75, 78, 99,
40), Date = structure(c(17784, 17791, 17798, 17805, 17812,
17819, 17826, 17833, 17608, 17615, 17622, 17629, 17636), class = "Date")), row.names = c(NA,
-13L), class = "data.frame")
I have so many customers of data from different state with different start and end dates.
I'd like to convert this data to time_series data and perform exponential smoothing using hw
method.
The code which I have tried to convert to time_series is:
temp <- multiple_ts %>%
group_by(state,customer_id) %>%
ts(multiple_ts$value, frequency = 52)
I used frequency as 52 because the data is weekly_data,but the code is throwing an error
Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
my output_data is
structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20.4, 29,
26, 40, 35, 36, 28, 41, 70, 75, 78, 99, 40, 17784, 17791, 17798,
17805, 17812, 17819, 17826, 17833, 17608, 17615, 17622, 17629,
17636), .Dim = c(13L, 4L), .Dimnames = list(NULL, c("customer_id",
"state", "value", "Date")), .Tsp = c(20.9384615384615, 21.1692307692308,
52), class = c("mts", "ts", "matrix"))
Can someone help me in R.
Thanks in Advance
r dplyr time-series smoothing exponential
Here is the structure of my data
structure(list(customer_id = c("A", "A", "A", "A", "A", "A",
"A", "A", "B", "B", "B", "B", "B"), state = c("NC", "NC", "NC",
"NC", "NC", "NC", "NC", "NC", "KA", "KA", "KA", "KA", "KA"),
value = c(20.4, 29, 26, 40, 35, 36, 28, 41, 70, 75, 78, 99,
40), Date = structure(c(17784, 17791, 17798, 17805, 17812,
17819, 17826, 17833, 17608, 17615, 17622, 17629, 17636), class = "Date")), row.names = c(NA,
-13L), class = "data.frame")
I have so many customers of data from different state with different start and end dates.
I'd like to convert this data to time_series data and perform exponential smoothing using hw
method.
The code which I have tried to convert to time_series is:
temp <- multiple_ts %>%
group_by(state,customer_id) %>%
ts(multiple_ts$value, frequency = 52)
I used frequency as 52 because the data is weekly_data,but the code is throwing an error
Warning messages:
1: In data.matrix(data) : NAs introduced by coercion
2: In data.matrix(data) : NAs introduced by coercion
my output_data is
structure(c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20.4, 29,
26, 40, 35, 36, 28, 41, 70, 75, 78, 99, 40, 17784, 17791, 17798,
17805, 17812, 17819, 17826, 17833, 17608, 17615, 17622, 17629,
17636), .Dim = c(13L, 4L), .Dimnames = list(NULL, c("customer_id",
"state", "value", "Date")), .Tsp = c(20.9384615384615, 21.1692307692308,
52), class = c("mts", "ts", "matrix"))
Can someone help me in R.
Thanks in Advance
r dplyr time-series smoothing exponential
r dplyr time-series smoothing exponential
edited Nov 12 '18 at 3:04
asked Nov 12 '18 at 2:49
Lalitha
106
106
1
Those aren't errors, they're warnings. There might be nothing wrong except you haveNA
values.
– thelatemail
Nov 12 '18 at 2:52
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
Trying to combinets
anddplyr
'sgroup_by
doesn't seem to work. You end up with a malformedmatrix
. As per this question, you might be better using thexts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping -lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing usinghw
method it showed me asError in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail
– Lalitha
Nov 12 '18 at 3:59
I'm not sure how you ended up with a multiple time series. The code I pasted abovesplit
smultiple_ts$value
, which results in the required "univariate time series". Did you split the wholemultiple_ts
ormultiple_ts$value
?
– thelatemail
Nov 12 '18 at 4:11
|
show 3 more comments
1
Those aren't errors, they're warnings. There might be nothing wrong except you haveNA
values.
– thelatemail
Nov 12 '18 at 2:52
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
Trying to combinets
anddplyr
'sgroup_by
doesn't seem to work. You end up with a malformedmatrix
. As per this question, you might be better using thexts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping -lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing usinghw
method it showed me asError in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail
– Lalitha
Nov 12 '18 at 3:59
I'm not sure how you ended up with a multiple time series. The code I pasted abovesplit
smultiple_ts$value
, which results in the required "univariate time series". Did you split the wholemultiple_ts
ormultiple_ts$value
?
– thelatemail
Nov 12 '18 at 4:11
1
1
Those aren't errors, they're warnings. There might be nothing wrong except you have
NA
values.– thelatemail
Nov 12 '18 at 2:52
Those aren't errors, they're warnings. There might be nothing wrong except you have
NA
values.– thelatemail
Nov 12 '18 at 2:52
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
Trying to combine
ts
and dplyr
's group_by
doesn't seem to work. You end up with a malformed matrix
. As per this question, you might be better using the xts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping - lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
Trying to combine
ts
and dplyr
's group_by
doesn't seem to work. You end up with a malformed matrix
. As per this question, you might be better using the xts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping - lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing using
hw
method it showed me as Error in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail– Lalitha
Nov 12 '18 at 3:59
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing using
hw
method it showed me as Error in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail– Lalitha
Nov 12 '18 at 3:59
I'm not sure how you ended up with a multiple time series. The code I pasted above
split
s multiple_ts$value
, which results in the required "univariate time series". Did you split the whole multiple_ts
or multiple_ts$value
?– thelatemail
Nov 12 '18 at 4:11
I'm not sure how you ended up with a multiple time series. The code I pasted above
split
s multiple_ts$value
, which results in the required "univariate time series". Did you split the whole multiple_ts
or multiple_ts$value
?– thelatemail
Nov 12 '18 at 4:11
|
show 3 more comments
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255381%2fconvert-multiple-ids-weekly-data-to-time-series-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255381%2fconvert-multiple-ids-weekly-data-to-time-series-format%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Those aren't errors, they're warnings. There might be nothing wrong except you have
NA
values.– thelatemail
Nov 12 '18 at 2:52
I edited the question and posted with output.Can you help me to overcome this problem and get a time_series data and apply exponential smoothing method in R@thelatemail
– Lalitha
Nov 12 '18 at 3:05
Trying to combine
ts
anddplyr
'sgroup_by
doesn't seem to work. You end up with a malformedmatrix
. As per this question, you might be better using thexts
package's time-series - stackoverflow.com/questions/28489845/… . Or maybe revert to basic looping -lapply(split(multiple_ts$value, multiple_ts[c("state","customer_id")], drop=TRUE), ts, frequency=52)
– thelatemail
Nov 12 '18 at 3:24
I tried the basic looping but I didn't work with larger number of series of data,apart from this also when I tried for exponential_smoothing using
hw
method it showed me asError in ets(x, "AAN", alpha = alpha, beta = beta, phi = phi, damped = damped, : y should be a univariate time series
how can we apply exponential series to multiple time_series of data.Can you help me@thelatemail– Lalitha
Nov 12 '18 at 3:59
I'm not sure how you ended up with a multiple time series. The code I pasted above
split
smultiple_ts$value
, which results in the required "univariate time series". Did you split the wholemultiple_ts
ormultiple_ts$value
?– thelatemail
Nov 12 '18 at 4:11