R timeseries dataset. Merge new data with old as if timestamp_new >= Timestamp_old and if ID_new >...












0















(Question in the end)
I have a table like this one:



   Date          Period  ID Multi    Volume Price 
16/01/2019 1 1 -5124.00 -300 34.16
16/01/2019 2 1 -5124.00 -300 34.16
16/01/2019 2 2 -993.30 -60 33.11
16/01/2019 2 3 -4783.00 -200 47.83
16/01/2019 2 4 5906.25 150 78.75
16/01/2019 2 5 -3342.50 -382 17.50
16/01/2019 2 6 8745.00 220 79.50
16/01/2019 2 7 16050.00 300 107.00
16/01/2019 3 1 -5124.00 -300 34.16
16/01/2019 3 2 -993.30 -60 33.11
16/01/2019 3 3 -3955.00 -200 39.55


Period is hours. When new data is published can both contain new data for example Hour 4 ID 1 but also for hour 2 and then the new data recives the ID 8 for Hour 2.



The new data would then look like this. It does no longer show hour one because it belongs to the past. it shows a new observation for hour2 hour5, no for H4.



   Date          Period  ID Multi    Volume Price   
16/01/2019 2 1 -5124.00 -300 34.16
16/01/2019 2 2 -993.30 -60 33.11
16/01/2019 2 3 -4783.00 -200 47.83
16/01/2019 2 4 5906.25 150 78.75
16/01/2019 2 5 -3342.50 -382 17.50
16/01/2019 2 6 8745.00 220 79.50
16/01/2019 2 7 16050.00 300 107.00
15/01/2019 2 8 16050.00 300 107.00
16/01/2019 3 1 -5124.00 -300 34.16
16/01/2019 3 2 -993.30 -60 33.11
16/01/2019 3 3 -3955.00 -200 39.55
16/01/2019 5 1 -3955.00 -200 39.55


How do I merge the new data with the old.
Extra info is that I on some days dont recive any new info.



The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file



I just want to open the old dataset and write something like



 if Date_new = Date_old Then
If Period_new = period_old Then
IF ID_new > ID_old Then
Add the new rows to old dataset.
end if
else if Perioed_new > period_old Then
Add the new rows to old dataset
end if
else if Date New > Date_old then
Add the new rows to old dataset
end if

sort dataset by date -> period -> ID.
save dataset.


Im transition to R from matlab and imstuck with this part.
I can get it to look if there is a csv then open the csv's transfrom the raw data into the structure i want and save it to an database.



Hope somebody can give a few hints on how to model the dateset. I spent Hours looking for at solution to this relatively simple problem...



Best
Frederik










share|improve this question





























    0















    (Question in the end)
    I have a table like this one:



       Date          Period  ID Multi    Volume Price 
    16/01/2019 1 1 -5124.00 -300 34.16
    16/01/2019 2 1 -5124.00 -300 34.16
    16/01/2019 2 2 -993.30 -60 33.11
    16/01/2019 2 3 -4783.00 -200 47.83
    16/01/2019 2 4 5906.25 150 78.75
    16/01/2019 2 5 -3342.50 -382 17.50
    16/01/2019 2 6 8745.00 220 79.50
    16/01/2019 2 7 16050.00 300 107.00
    16/01/2019 3 1 -5124.00 -300 34.16
    16/01/2019 3 2 -993.30 -60 33.11
    16/01/2019 3 3 -3955.00 -200 39.55


    Period is hours. When new data is published can both contain new data for example Hour 4 ID 1 but also for hour 2 and then the new data recives the ID 8 for Hour 2.



    The new data would then look like this. It does no longer show hour one because it belongs to the past. it shows a new observation for hour2 hour5, no for H4.



       Date          Period  ID Multi    Volume Price   
    16/01/2019 2 1 -5124.00 -300 34.16
    16/01/2019 2 2 -993.30 -60 33.11
    16/01/2019 2 3 -4783.00 -200 47.83
    16/01/2019 2 4 5906.25 150 78.75
    16/01/2019 2 5 -3342.50 -382 17.50
    16/01/2019 2 6 8745.00 220 79.50
    16/01/2019 2 7 16050.00 300 107.00
    15/01/2019 2 8 16050.00 300 107.00
    16/01/2019 3 1 -5124.00 -300 34.16
    16/01/2019 3 2 -993.30 -60 33.11
    16/01/2019 3 3 -3955.00 -200 39.55
    16/01/2019 5 1 -3955.00 -200 39.55


    How do I merge the new data with the old.
    Extra info is that I on some days dont recive any new info.



    The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file



    I just want to open the old dataset and write something like



     if Date_new = Date_old Then
    If Period_new = period_old Then
    IF ID_new > ID_old Then
    Add the new rows to old dataset.
    end if
    else if Perioed_new > period_old Then
    Add the new rows to old dataset
    end if
    else if Date New > Date_old then
    Add the new rows to old dataset
    end if

    sort dataset by date -> period -> ID.
    save dataset.


    Im transition to R from matlab and imstuck with this part.
    I can get it to look if there is a csv then open the csv's transfrom the raw data into the structure i want and save it to an database.



    Hope somebody can give a few hints on how to model the dateset. I spent Hours looking for at solution to this relatively simple problem...



    Best
    Frederik










    share|improve this question



























      0












      0








      0








      (Question in the end)
      I have a table like this one:



         Date          Period  ID Multi    Volume Price 
      16/01/2019 1 1 -5124.00 -300 34.16
      16/01/2019 2 1 -5124.00 -300 34.16
      16/01/2019 2 2 -993.30 -60 33.11
      16/01/2019 2 3 -4783.00 -200 47.83
      16/01/2019 2 4 5906.25 150 78.75
      16/01/2019 2 5 -3342.50 -382 17.50
      16/01/2019 2 6 8745.00 220 79.50
      16/01/2019 2 7 16050.00 300 107.00
      16/01/2019 3 1 -5124.00 -300 34.16
      16/01/2019 3 2 -993.30 -60 33.11
      16/01/2019 3 3 -3955.00 -200 39.55


      Period is hours. When new data is published can both contain new data for example Hour 4 ID 1 but also for hour 2 and then the new data recives the ID 8 for Hour 2.



      The new data would then look like this. It does no longer show hour one because it belongs to the past. it shows a new observation for hour2 hour5, no for H4.



         Date          Period  ID Multi    Volume Price   
      16/01/2019 2 1 -5124.00 -300 34.16
      16/01/2019 2 2 -993.30 -60 33.11
      16/01/2019 2 3 -4783.00 -200 47.83
      16/01/2019 2 4 5906.25 150 78.75
      16/01/2019 2 5 -3342.50 -382 17.50
      16/01/2019 2 6 8745.00 220 79.50
      16/01/2019 2 7 16050.00 300 107.00
      15/01/2019 2 8 16050.00 300 107.00
      16/01/2019 3 1 -5124.00 -300 34.16
      16/01/2019 3 2 -993.30 -60 33.11
      16/01/2019 3 3 -3955.00 -200 39.55
      16/01/2019 5 1 -3955.00 -200 39.55


      How do I merge the new data with the old.
      Extra info is that I on some days dont recive any new info.



      The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file



      I just want to open the old dataset and write something like



       if Date_new = Date_old Then
      If Period_new = period_old Then
      IF ID_new > ID_old Then
      Add the new rows to old dataset.
      end if
      else if Perioed_new > period_old Then
      Add the new rows to old dataset
      end if
      else if Date New > Date_old then
      Add the new rows to old dataset
      end if

      sort dataset by date -> period -> ID.
      save dataset.


      Im transition to R from matlab and imstuck with this part.
      I can get it to look if there is a csv then open the csv's transfrom the raw data into the structure i want and save it to an database.



      Hope somebody can give a few hints on how to model the dateset. I spent Hours looking for at solution to this relatively simple problem...



      Best
      Frederik










      share|improve this question
















      (Question in the end)
      I have a table like this one:



         Date          Period  ID Multi    Volume Price 
      16/01/2019 1 1 -5124.00 -300 34.16
      16/01/2019 2 1 -5124.00 -300 34.16
      16/01/2019 2 2 -993.30 -60 33.11
      16/01/2019 2 3 -4783.00 -200 47.83
      16/01/2019 2 4 5906.25 150 78.75
      16/01/2019 2 5 -3342.50 -382 17.50
      16/01/2019 2 6 8745.00 220 79.50
      16/01/2019 2 7 16050.00 300 107.00
      16/01/2019 3 1 -5124.00 -300 34.16
      16/01/2019 3 2 -993.30 -60 33.11
      16/01/2019 3 3 -3955.00 -200 39.55


      Period is hours. When new data is published can both contain new data for example Hour 4 ID 1 but also for hour 2 and then the new data recives the ID 8 for Hour 2.



      The new data would then look like this. It does no longer show hour one because it belongs to the past. it shows a new observation for hour2 hour5, no for H4.



         Date          Period  ID Multi    Volume Price   
      16/01/2019 2 1 -5124.00 -300 34.16
      16/01/2019 2 2 -993.30 -60 33.11
      16/01/2019 2 3 -4783.00 -200 47.83
      16/01/2019 2 4 5906.25 150 78.75
      16/01/2019 2 5 -3342.50 -382 17.50
      16/01/2019 2 6 8745.00 220 79.50
      16/01/2019 2 7 16050.00 300 107.00
      15/01/2019 2 8 16050.00 300 107.00
      16/01/2019 3 1 -5124.00 -300 34.16
      16/01/2019 3 2 -993.30 -60 33.11
      16/01/2019 3 3 -3955.00 -200 39.55
      16/01/2019 5 1 -3955.00 -200 39.55


      How do I merge the new data with the old.
      Extra info is that I on some days dont recive any new info.



      The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file



      I just want to open the old dataset and write something like



       if Date_new = Date_old Then
      If Period_new = period_old Then
      IF ID_new > ID_old Then
      Add the new rows to old dataset.
      end if
      else if Perioed_new > period_old Then
      Add the new rows to old dataset
      end if
      else if Date New > Date_old then
      Add the new rows to old dataset
      end if

      sort dataset by date -> period -> ID.
      save dataset.


      Im transition to R from matlab and imstuck with this part.
      I can get it to look if there is a csv then open the csv's transfrom the raw data into the structure i want and save it to an database.



      Hope somebody can give a few hints on how to model the dateset. I spent Hours looking for at solution to this relatively simple problem...



      Best
      Frederik







      r database merge dataset






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 20 at 0:11







      TheFrederik

















      asked Jan 19 at 20:40









      TheFrederikTheFrederik

      12




      12
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I cannot comment with my low rep so I will delete this soon. The behavior of your new data (how something is assigned an "8" versus something else), and the behavior of your current and new data (e.g., is your data live and is writing new files every X hours, or is it overwriting these files?) What is your end goal (are you trying to import all the files into R to manipulate/analyse)?



          Providing a reproducible example will probably help you improve the clarity of your question.






          share|improve this answer
























          • Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

            – TheFrederik
            Jan 20 at 0:07





















          0














          finally...



          I love packages but they are making me lazy.



          library(gtools)



          mydata <- smartbind(data1, data2) ' binds the data together in a clever fashion.



          library(tidyverse)



          cleanmydata <- mydata %>% distinct() ' cleans rows containing the same values in all columns.



          done






          share|improve this answer























            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%2f54271204%2fr-timeseries-dataset-merge-new-data-with-old-as-if-timestamp-new-timestamp-o%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









            0














            I cannot comment with my low rep so I will delete this soon. The behavior of your new data (how something is assigned an "8" versus something else), and the behavior of your current and new data (e.g., is your data live and is writing new files every X hours, or is it overwriting these files?) What is your end goal (are you trying to import all the files into R to manipulate/analyse)?



            Providing a reproducible example will probably help you improve the clarity of your question.






            share|improve this answer
























            • Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

              – TheFrederik
              Jan 20 at 0:07


















            0














            I cannot comment with my low rep so I will delete this soon. The behavior of your new data (how something is assigned an "8" versus something else), and the behavior of your current and new data (e.g., is your data live and is writing new files every X hours, or is it overwriting these files?) What is your end goal (are you trying to import all the files into R to manipulate/analyse)?



            Providing a reproducible example will probably help you improve the clarity of your question.






            share|improve this answer
























            • Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

              – TheFrederik
              Jan 20 at 0:07
















            0












            0








            0







            I cannot comment with my low rep so I will delete this soon. The behavior of your new data (how something is assigned an "8" versus something else), and the behavior of your current and new data (e.g., is your data live and is writing new files every X hours, or is it overwriting these files?) What is your end goal (are you trying to import all the files into R to manipulate/analyse)?



            Providing a reproducible example will probably help you improve the clarity of your question.






            share|improve this answer













            I cannot comment with my low rep so I will delete this soon. The behavior of your new data (how something is assigned an "8" versus something else), and the behavior of your current and new data (e.g., is your data live and is writing new files every X hours, or is it overwriting these files?) What is your end goal (are you trying to import all the files into R to manipulate/analyse)?



            Providing a reproducible example will probably help you improve the clarity of your question.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 19 at 21:17









            Jessica BurnettJessica Burnett

            115




            115













            • Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

              – TheFrederik
              Jan 20 at 0:07





















            • Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

              – TheFrederik
              Jan 20 at 0:07



















            Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

            – TheFrederik
            Jan 20 at 0:07







            Hi Jessica. I'll try to improve it. The ID is trades for that hour. Every new trade for a specific hours gets an new trade ID. I get the data every time there is (a) new trade(s). Trades can happen 24 hours in advance.. When a new trade has happend I recive the CSV file with all confirmed trades from now to +24H and not only the new trade. LIke the table i showed. So I have to finde the difference between the old dataset and the new csv file and then add that new row/rows to the old dataset and wait until I receive a new csv file.

            – TheFrederik
            Jan 20 at 0:07















            0














            finally...



            I love packages but they are making me lazy.



            library(gtools)



            mydata <- smartbind(data1, data2) ' binds the data together in a clever fashion.



            library(tidyverse)



            cleanmydata <- mydata %>% distinct() ' cleans rows containing the same values in all columns.



            done






            share|improve this answer




























              0














              finally...



              I love packages but they are making me lazy.



              library(gtools)



              mydata <- smartbind(data1, data2) ' binds the data together in a clever fashion.



              library(tidyverse)



              cleanmydata <- mydata %>% distinct() ' cleans rows containing the same values in all columns.



              done






              share|improve this answer


























                0












                0








                0







                finally...



                I love packages but they are making me lazy.



                library(gtools)



                mydata <- smartbind(data1, data2) ' binds the data together in a clever fashion.



                library(tidyverse)



                cleanmydata <- mydata %>% distinct() ' cleans rows containing the same values in all columns.



                done






                share|improve this answer













                finally...



                I love packages but they are making me lazy.



                library(gtools)



                mydata <- smartbind(data1, data2) ' binds the data together in a clever fashion.



                library(tidyverse)



                cleanmydata <- mydata %>% distinct() ' cleans rows containing the same values in all columns.



                done







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 20 at 1:46









                TheFrederikTheFrederik

                12




                12






























                    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%2f54271204%2fr-timeseries-dataset-merge-new-data-with-old-as-if-timestamp-new-timestamp-o%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

                    Callistus III

                    Ostreoida

                    Plistias Cous