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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현