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













0















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









share|improve this question


























    0















    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









    share|improve this question
























      0












      0








      0








      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









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      cs0815cs0815

      5,4081978205




      5,4081978205






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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





          share|improve this answer






























            -1














            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





            share|improve this answer

























            • 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 on value 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










            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
            );



            );













            draft saved

            draft discarded


















            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









            1














            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





            share|improve this answer



























              1














              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





              share|improve this answer

























                1












                1








                1







                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





                share|improve this answer













                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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                SotosSotos

                31k51741




                31k51741























                    -1














                    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





                    share|improve this answer

























                    • 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 on value 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















                    -1














                    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





                    share|improve this answer

























                    • 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 on value 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













                    -1












                    -1








                    -1







                    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





                    share|improve this answer















                    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






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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 on value 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






                    • 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






                    • 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

















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript