Count and summarise ID's each day while creating a new column that shows the accumulated ID'sHow to simulate customer walk-ins for a given period in a fast food chain in RCreate multiple matrices from 2 bigger ones in RProbability of what product will be purchased in repeat ordersEcho-Effect-Metric Networkk-Nearest Neighbours with time series data - how to obtain whole-time-period estimatorsConvert from many sub-tables to a single tidy dataframeLook for previous date in dataframe that has certain column category in RWhat is the difference between Missing at Random and Missing not at Random data?R summarise with conditionplot the histogram of purchases

What term is being referred to with "reflected-sound-of-underground-spirits"?

Can I criticise the more senior developers around me for not writing clean code?

A strange hotel

How to fry ground beef so it is well-browned

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Do I have an "anti-research" personality?

Don’t seats that recline flat defeat the purpose of having seatbelts?

How come there are so many candidates for the 2020 Democratic party presidential nomination?

Does a large simulator bay have standard public address announcements?

How to limit Drive Letters Windows assigns to new removable USB drives

Equally distributed table columns

Big O /Right or wrong?

"The cow" OR "a cow" OR "cows" in this context

Check if a string is entirely made of the same substring

How do I reattach a shelf to the wall when it ripped out of the wall?

Farming on the moon

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Why did C use the -> operator instead of reusing the . operator?

How do I produce this Greek letter koppa: Ϟ in pdfLaTeX?

Retract an already submitted recommendation letter (written for an undergrad student)

Is there any official lore on the Far Realm?

Determine the application client is using to connect

What to do with someone that cheated their way through university and a PhD program?

'It addicted me, with one taste.' Can 'addict' be used transitively?



Count and summarise ID's each day while creating a new column that shows the accumulated ID's


How to simulate customer walk-ins for a given period in a fast food chain in RCreate multiple matrices from 2 bigger ones in RProbability of what product will be purchased in repeat ordersEcho-Effect-Metric Networkk-Nearest Neighbours with time series data - how to obtain whole-time-period estimatorsConvert from many sub-tables to a single tidy dataframeLook for previous date in dataframe that has certain column category in RWhat is the difference between Missing at Random and Missing not at Random data?R summarise with conditionplot the histogram of purchases













2












$begingroup$


I have two column, first one being the ID of a customer and second one being the Date of purchase.



 ID Date
1 2017-01-17
2 2017-01-17
3 2017-01-17
4 2017-01-17
5 2017-01-17
1 2017-01-17
7 2017-01-17
1 2017-01-17
9 2017-01-18
2 2017-01-18
3 2017-01-18
5 2017-01-18
1 2017-01-18
2 2017-01-18


I would like to summarise the Purchases made by a Customer at one day and create a third column that shows the amount of purchases for the customer on that date.










share|improve this question











$endgroup$
















    2












    $begingroup$


    I have two column, first one being the ID of a customer and second one being the Date of purchase.



     ID Date
    1 2017-01-17
    2 2017-01-17
    3 2017-01-17
    4 2017-01-17
    5 2017-01-17
    1 2017-01-17
    7 2017-01-17
    1 2017-01-17
    9 2017-01-18
    2 2017-01-18
    3 2017-01-18
    5 2017-01-18
    1 2017-01-18
    2 2017-01-18


    I would like to summarise the Purchases made by a Customer at one day and create a third column that shows the amount of purchases for the customer on that date.










    share|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      I have two column, first one being the ID of a customer and second one being the Date of purchase.



       ID Date
      1 2017-01-17
      2 2017-01-17
      3 2017-01-17
      4 2017-01-17
      5 2017-01-17
      1 2017-01-17
      7 2017-01-17
      1 2017-01-17
      9 2017-01-18
      2 2017-01-18
      3 2017-01-18
      5 2017-01-18
      1 2017-01-18
      2 2017-01-18


      I would like to summarise the Purchases made by a Customer at one day and create a third column that shows the amount of purchases for the customer on that date.










      share|improve this question











      $endgroup$




      I have two column, first one being the ID of a customer and second one being the Date of purchase.



       ID Date
      1 2017-01-17
      2 2017-01-17
      3 2017-01-17
      4 2017-01-17
      5 2017-01-17
      1 2017-01-17
      7 2017-01-17
      1 2017-01-17
      9 2017-01-18
      2 2017-01-18
      3 2017-01-18
      5 2017-01-18
      1 2017-01-18
      2 2017-01-18


      I would like to summarise the Purchases made by a Customer at one day and create a third column that shows the amount of purchases for the customer on that date.







      r






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 15 hours ago









      Stephen Rauch

      1,52551330




      1,52551330










      asked Apr 6 at 11:54









      JelleManneJelleManne

      112




      112




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          This is a base solution for your problem:



          aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)


          there are many more solutions like any of the ones below, using dplyr:



          library(dplyr)
          df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
          df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
          df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
          df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
          df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")


          or by using data.table package:



          library(data.table)
          setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]


          or using sqldf package:



          library(sqldf)
          sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
          FROM df
          GROUP BY Date, ID")


          or plyr:



          plyr::count(df, c('ID','Date'))


          I personally prefer data.table as it is directly writes to the dataframe and often is time efficient. aggregate is also favorable when you wanna avoid loading new libraries. dplyr generally make your code more legible as it uses pipingpersonal opinion.






          share|improve this answer









          $endgroup$













            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "557"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fdatascience.stackexchange.com%2fquestions%2f48740%2fcount-and-summarise-ids-each-day-while-creating-a-new-column-that-shows-the-acc%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









            0












            $begingroup$

            This is a base solution for your problem:



            aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)


            there are many more solutions like any of the ones below, using dplyr:



            library(dplyr)
            df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
            df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
            df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
            df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
            df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")


            or by using data.table package:



            library(data.table)
            setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]


            or using sqldf package:



            library(sqldf)
            sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
            FROM df
            GROUP BY Date, ID")


            or plyr:



            plyr::count(df, c('ID','Date'))


            I personally prefer data.table as it is directly writes to the dataframe and often is time efficient. aggregate is also favorable when you wanna avoid loading new libraries. dplyr generally make your code more legible as it uses pipingpersonal opinion.






            share|improve this answer









            $endgroup$

















              0












              $begingroup$

              This is a base solution for your problem:



              aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)


              there are many more solutions like any of the ones below, using dplyr:



              library(dplyr)
              df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
              df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
              df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
              df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
              df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")


              or by using data.table package:



              library(data.table)
              setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]


              or using sqldf package:



              library(sqldf)
              sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
              FROM df
              GROUP BY Date, ID")


              or plyr:



              plyr::count(df, c('ID','Date'))


              I personally prefer data.table as it is directly writes to the dataframe and often is time efficient. aggregate is also favorable when you wanna avoid loading new libraries. dplyr generally make your code more legible as it uses pipingpersonal opinion.






              share|improve this answer









              $endgroup$















                0












                0








                0





                $begingroup$

                This is a base solution for your problem:



                aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)


                there are many more solutions like any of the ones below, using dplyr:



                library(dplyr)
                df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
                df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")


                or by using data.table package:



                library(data.table)
                setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]


                or using sqldf package:



                library(sqldf)
                sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
                FROM df
                GROUP BY Date, ID")


                or plyr:



                plyr::count(df, c('ID','Date'))


                I personally prefer data.table as it is directly writes to the dataframe and often is time efficient. aggregate is also favorable when you wanna avoid loading new libraries. dplyr generally make your code more legible as it uses pipingpersonal opinion.






                share|improve this answer









                $endgroup$



                This is a base solution for your problem:



                aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)


                there are many more solutions like any of the ones below, using dplyr:



                library(dplyr)
                df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
                df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
                df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")


                or by using data.table package:



                library(data.table)
                setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]


                or using sqldf package:



                library(sqldf)
                sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
                FROM df
                GROUP BY Date, ID")


                or plyr:



                plyr::count(df, c('ID','Date'))


                I personally prefer data.table as it is directly writes to the dataframe and often is time efficient. aggregate is also favorable when you wanna avoid loading new libraries. dplyr generally make your code more legible as it uses pipingpersonal opinion.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 19 hours ago









                M-MM-M

                15010




                15010



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Data Science Stack Exchange!


                    • 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.

                    Use MathJax to format equations. MathJax reference.


                    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%2fdatascience.stackexchange.com%2fquestions%2f48740%2fcount-and-summarise-ids-each-day-while-creating-a-new-column-that-shows-the-acc%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

                    Marja Vauras Lähteet | Aiheesta muualla | NavigointivalikkoMarja Vauras Turun yliopiston tutkimusportaalissaInfobox OKSuomalaisen Tiedeakatemian varsinaiset jäsenetKasvatustieteiden tiedekunnan dekaanit ja muu johtoMarja VaurasKoulutusvienti on kestävyys- ja ketteryyslaji (2.5.2017)laajentamallaWorldCat Identities0000 0001 0855 9405n86069603utb201588738523620927

                    Which is better: GPT or RelGAN for text generation?2019 Community Moderator ElectionWhat is the difference between TextGAN and LM for text generation?GANs (generative adversarial networks) possible for text as well?Generator loss not decreasing- text to image synthesisChoosing a right algorithm for template-based text generationHow should I format input and output for text generation with LSTMsGumbel Softmax vs Vanilla Softmax for GAN trainingWhich neural network to choose for classification from text/speech?NLP text autoencoder that generates text in poetic meterWhat is the interpretation of the expectation notation in the GAN formulation?What is the difference between TextGAN and LM for text generation?How to prepare the data for text generation task

                    Is this part of the description of the Archfey warlock's Misty Escape feature redundant?When is entropic ward considered “used”?How does the reaction timing work for Wrath of the Storm? Can it potentially prevent the damage from the triggering attack?Does the Dark Arts Archlich warlock patrons's Arcane Invisibility activate every time you cast a level 1+ spell?When attacking while invisible, when exactly does invisibility break?Can I cast Hellish Rebuke on my turn?Do I have to “pre-cast” a reaction spell in order for it to be triggered?What happens if a Player Misty Escapes into an Invisible CreatureCan a reaction interrupt multiattack?Does the Fiend-patron warlock's Hurl Through Hell feature dispel effects that require the target to be on the same plane as the caster?What are you allowed to do while using the Warlock's Eldritch Master feature?