sum up values of compressed time series over timeRolling sum of time series with factorCan dplyr summarise over several variables without listing each one?R Calculate date based on dates in sequential rows in a data framedplyr summarise over nested group_byGroup rows based on gaps in time seriesAggregating to String and Summing the Values Associated to Aggregate in R 3.3.0 Dplyr v 0.5.0r - Subsetting time-series data.frame based on time and thresholdUsing dplyr in R to create multiple summarise(s)Time series to data frameSelect a time period by day and month
What if a revenant (monster) gains fire resistance?
Can disgust be a key component of horror?
How can mimic phobia be cured?
Does Doodling or Improvising on the Piano Have Any Benefits?
Why is so much work done on numerical verification of the Riemann Hypothesis?
Did arcade monitors have same pixel aspect ratio as TV sets?
Novel, Lo Tech SF/Fantasy
User Story breakdown - Technical Task + User Feature
What are the balance implications behind making invisible things auto-hide?
How could a planet have erratic days?
Why "had" in "[something] we would have made had we used [something]"?
Probability that THHT occurs in a sequence of 10 coin tosses
Strong empirical falsification of quantum mechanics based on vacuum energy density
Temporarily disable WLAN internet access for children, but allow it for adults
Lowest total scrabble score
Angel of Condemnation - Exile creature with second ability
How should I respond when I lied about my education and the company finds out through background check?
Recommended PCB layout understanding - ADM2572 datasheet
How to explain what's wrong with this application of the chain rule?
It grows, but water kills it
How to say when an application is taking the half of your screen on a computer
Why is it that I can sometimes guess the next note?
Are Captain Marvel's powers affected by Thanos' actions in Infinity War
What should you do if you miss a job interview (deliberately)?
sum up values of compressed time series over time
Rolling sum of time series with factorCan dplyr summarise over several variables without listing each one?R Calculate date based on dates in sequential rows in a data framedplyr summarise over nested group_byGroup rows based on gaps in time seriesAggregating to String and Summing the Values Associated to Aggregate in R 3.3.0 Dplyr v 0.5.0r - Subsetting time-series data.frame based on time and thresholdUsing dplyr in R to create multiple summarise(s)Time series to data frameSelect a time period by day and month
I try to describe my problem via the code below. I have a data frame of a 'compressed' time series in the form of data frame: have. It contains the start and end date of a period with a value over time. I want to repeat the data as in data frame: want to ultimately get to the data frame: ultimately_want which sums up the value over time. Maybe I do not need want and get straight to ultimately_want somehow? Thanks.
library(dplyr)
start_date <- as.Date(c("2004-08-02", "2004-08-03"))
end_date <- as.Date(c("2004-08-04", "2004-08-05"))
value <- c(5, 6)
have <- data.frame(start_date, end_date, value)
have
date <- as.Date(c("2004-08-02", "2004-08-03", "2004-08-04", "2004-08-03", "2004-08-04", "2004-08-05"))
value <- c(5, 5, 5, 6, 6, 6)
want <- data.frame(date, value)
want
ultimately_want <- want %>%
group_by(date) %>%
summarise(total = sum(value))
ultimately_want
r
add a comment |
I try to describe my problem via the code below. I have a data frame of a 'compressed' time series in the form of data frame: have. It contains the start and end date of a period with a value over time. I want to repeat the data as in data frame: want to ultimately get to the data frame: ultimately_want which sums up the value over time. Maybe I do not need want and get straight to ultimately_want somehow? Thanks.
library(dplyr)
start_date <- as.Date(c("2004-08-02", "2004-08-03"))
end_date <- as.Date(c("2004-08-04", "2004-08-05"))
value <- c(5, 6)
have <- data.frame(start_date, end_date, value)
have
date <- as.Date(c("2004-08-02", "2004-08-03", "2004-08-04", "2004-08-03", "2004-08-04", "2004-08-05"))
value <- c(5, 5, 5, 6, 6, 6)
want <- data.frame(date, value)
want
ultimately_want <- want %>%
group_by(date) %>%
summarise(total = sum(value))
ultimately_want
r
add a comment |
I try to describe my problem via the code below. I have a data frame of a 'compressed' time series in the form of data frame: have. It contains the start and end date of a period with a value over time. I want to repeat the data as in data frame: want to ultimately get to the data frame: ultimately_want which sums up the value over time. Maybe I do not need want and get straight to ultimately_want somehow? Thanks.
library(dplyr)
start_date <- as.Date(c("2004-08-02", "2004-08-03"))
end_date <- as.Date(c("2004-08-04", "2004-08-05"))
value <- c(5, 6)
have <- data.frame(start_date, end_date, value)
have
date <- as.Date(c("2004-08-02", "2004-08-03", "2004-08-04", "2004-08-03", "2004-08-04", "2004-08-05"))
value <- c(5, 5, 5, 6, 6, 6)
want <- data.frame(date, value)
want
ultimately_want <- want %>%
group_by(date) %>%
summarise(total = sum(value))
ultimately_want
r
I try to describe my problem via the code below. I have a data frame of a 'compressed' time series in the form of data frame: have. It contains the start and end date of a period with a value over time. I want to repeat the data as in data frame: want to ultimately get to the data frame: ultimately_want which sums up the value over time. Maybe I do not need want and get straight to ultimately_want somehow? Thanks.
library(dplyr)
start_date <- as.Date(c("2004-08-02", "2004-08-03"))
end_date <- as.Date(c("2004-08-04", "2004-08-05"))
value <- c(5, 6)
have <- data.frame(start_date, end_date, value)
have
date <- as.Date(c("2004-08-02", "2004-08-03", "2004-08-04", "2004-08-03", "2004-08-04", "2004-08-05"))
value <- c(5, 5, 5, 6, 6, 6)
want <- data.frame(date, value)
want
ultimately_want <- want %>%
group_by(date) %>%
summarise(total = sum(value))
ultimately_want
r
r
asked yesterday
cs0815cs0815
5,4081978205
5,4081978205
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here is a data.table
approach,
library(data.table)
setDT(have)[, .(value = value, date = seq(start_date, end_date, by = "day")),
by = 1:nrow(have)][,.(total = sum(value)), date][]
# date total
#1: 2004-08-02 5
#2: 2004-08-03 11
#3: 2004-08-04 11
#4: 2004-08-05 6
add a comment |
We can do
library(dplyr)
library(tidyr)
mutate(have,rid=row_number()) %>% gather(key,date, -value,-rid) %>%
select(-key)%>%group_by(rid) %>% complete(value, date=full_seq(date,1)) %>%
group_by(date) %>% summarise(total = sum(value))
# A tibble: 4 x 2
date total
<date> <dbl>
1 2004-08-02 5
2 2004-08-03 11
3 2004-08-04 11
4 2004-08-05 6
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
The downvote is a bit excessive here. However, grouping onvalue
is an accident waiting to happen. Imagine this same dataframe but both values are 5...
– Sotos
yesterday
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
add a comment |
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%2f55280660%2fsum-up-values-of-compressed-time-series-over-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a data.table
approach,
library(data.table)
setDT(have)[, .(value = value, date = seq(start_date, end_date, by = "day")),
by = 1:nrow(have)][,.(total = sum(value)), date][]
# date total
#1: 2004-08-02 5
#2: 2004-08-03 11
#3: 2004-08-04 11
#4: 2004-08-05 6
add a comment |
Here is a data.table
approach,
library(data.table)
setDT(have)[, .(value = value, date = seq(start_date, end_date, by = "day")),
by = 1:nrow(have)][,.(total = sum(value)), date][]
# date total
#1: 2004-08-02 5
#2: 2004-08-03 11
#3: 2004-08-04 11
#4: 2004-08-05 6
add a comment |
Here is a data.table
approach,
library(data.table)
setDT(have)[, .(value = value, date = seq(start_date, end_date, by = "day")),
by = 1:nrow(have)][,.(total = sum(value)), date][]
# date total
#1: 2004-08-02 5
#2: 2004-08-03 11
#3: 2004-08-04 11
#4: 2004-08-05 6
Here is a data.table
approach,
library(data.table)
setDT(have)[, .(value = value, date = seq(start_date, end_date, by = "day")),
by = 1:nrow(have)][,.(total = sum(value)), date][]
# date total
#1: 2004-08-02 5
#2: 2004-08-03 11
#3: 2004-08-04 11
#4: 2004-08-05 6
answered yesterday
SotosSotos
31k51741
31k51741
add a comment |
add a comment |
We can do
library(dplyr)
library(tidyr)
mutate(have,rid=row_number()) %>% gather(key,date, -value,-rid) %>%
select(-key)%>%group_by(rid) %>% complete(value, date=full_seq(date,1)) %>%
group_by(date) %>% summarise(total = sum(value))
# A tibble: 4 x 2
date total
<date> <dbl>
1 2004-08-02 5
2 2004-08-03 11
3 2004-08-04 11
4 2004-08-05 6
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
The downvote is a bit excessive here. However, grouping onvalue
is an accident waiting to happen. Imagine this same dataframe but both values are 5...
– Sotos
yesterday
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
add a comment |
We can do
library(dplyr)
library(tidyr)
mutate(have,rid=row_number()) %>% gather(key,date, -value,-rid) %>%
select(-key)%>%group_by(rid) %>% complete(value, date=full_seq(date,1)) %>%
group_by(date) %>% summarise(total = sum(value))
# A tibble: 4 x 2
date total
<date> <dbl>
1 2004-08-02 5
2 2004-08-03 11
3 2004-08-04 11
4 2004-08-05 6
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
The downvote is a bit excessive here. However, grouping onvalue
is an accident waiting to happen. Imagine this same dataframe but both values are 5...
– Sotos
yesterday
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
add a comment |
We can do
library(dplyr)
library(tidyr)
mutate(have,rid=row_number()) %>% gather(key,date, -value,-rid) %>%
select(-key)%>%group_by(rid) %>% complete(value, date=full_seq(date,1)) %>%
group_by(date) %>% summarise(total = sum(value))
# A tibble: 4 x 2
date total
<date> <dbl>
1 2004-08-02 5
2 2004-08-03 11
3 2004-08-04 11
4 2004-08-05 6
We can do
library(dplyr)
library(tidyr)
mutate(have,rid=row_number()) %>% gather(key,date, -value,-rid) %>%
select(-key)%>%group_by(rid) %>% complete(value, date=full_seq(date,1)) %>%
group_by(date) %>% summarise(total = sum(value))
# A tibble: 4 x 2
date total
<date> <dbl>
1 2004-08-02 5
2 2004-08-03 11
3 2004-08-04 11
4 2004-08-05 6
edited yesterday
answered yesterday
A. SulimanA. Suliman
5,63241223
5,63241223
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
The downvote is a bit excessive here. However, grouping onvalue
is an accident waiting to happen. Imagine this same dataframe but both values are 5...
– Sotos
yesterday
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
add a comment |
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
The downvote is a bit excessive here. However, grouping onvalue
is an accident waiting to happen. Imagine this same dataframe but both values are 5...
– Sotos
yesterday
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
thanks but as far as I can tell/see this does not give me the running dates as in the df: ultimately_want
– cs0815
yesterday
1
1
The downvote is a bit excessive here. However, grouping on
value
is an accident waiting to happen. Imagine this same dataframe but both values are 5...– Sotos
yesterday
The downvote is a bit excessive here. However, grouping on
value
is an accident waiting to happen. Imagine this same dataframe but both values are 5...– Sotos
yesterday
1
1
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
@Sotos thanks I do agree with you on what you've said.
– A. Suliman
yesterday
add a comment |
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.
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%2f55280660%2fsum-up-values-of-compressed-time-series-over-time%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