Adding Rows in R for large dataset











up vote
1
down vote

favorite












I am new to R . I have a large dataset with 1-minute resolution for one year . It makes total of 55940 observation all 1 minute apart with dates and times . I want to change it to six minute resolution data. It necessarily means adding first 6 rows then next 6 and so on so forth . Any good solutions ?










share|improve this question







New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • add sample data or head(data)
    – sai saran
    Nov 8 at 10:28










  • What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
    – paoloeusebi
    Nov 8 at 10:46












  • Search for "rolling sum".
    – zx8754
    Nov 8 at 11:02















up vote
1
down vote

favorite












I am new to R . I have a large dataset with 1-minute resolution for one year . It makes total of 55940 observation all 1 minute apart with dates and times . I want to change it to six minute resolution data. It necessarily means adding first 6 rows then next 6 and so on so forth . Any good solutions ?










share|improve this question







New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • add sample data or head(data)
    – sai saran
    Nov 8 at 10:28










  • What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
    – paoloeusebi
    Nov 8 at 10:46












  • Search for "rolling sum".
    – zx8754
    Nov 8 at 11:02













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am new to R . I have a large dataset with 1-minute resolution for one year . It makes total of 55940 observation all 1 minute apart with dates and times . I want to change it to six minute resolution data. It necessarily means adding first 6 rows then next 6 and so on so forth . Any good solutions ?










share|improve this question







New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am new to R . I have a large dataset with 1-minute resolution for one year . It makes total of 55940 observation all 1 minute apart with dates and times . I want to change it to six minute resolution data. It necessarily means adding first 6 rows then next 6 and so on so forth . Any good solutions ?







r






share|improve this question







New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 8 at 10:26









Shah

61




61




New contributor




Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • add sample data or head(data)
    – sai saran
    Nov 8 at 10:28










  • What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
    – paoloeusebi
    Nov 8 at 10:46












  • Search for "rolling sum".
    – zx8754
    Nov 8 at 11:02


















  • add sample data or head(data)
    – sai saran
    Nov 8 at 10:28










  • What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
    – paoloeusebi
    Nov 8 at 10:46












  • Search for "rolling sum".
    – zx8754
    Nov 8 at 11:02
















add sample data or head(data)
– sai saran
Nov 8 at 10:28




add sample data or head(data)
– sai saran
Nov 8 at 10:28












What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46






What is your goal? You want end up with a dataset with less raws? Would you like average your values over each 6 rows interval? Would you like to pickup one row every six? Could this So question be useful? stackoverflow.com/questions/23279550/…
– paoloeusebi
Nov 8 at 10:46














Search for "rolling sum".
– zx8754
Nov 8 at 11:02




Search for "rolling sum".
– zx8754
Nov 8 at 11:02












2 Answers
2






active

oldest

votes

















up vote
1
down vote













You could try something like this:



library(dplyr)

# original df
df <- data.frame(min = 1:60, val = rnorm(60))

# create a grouping variable and add to df
grp <- floor(df$min / 6)
df <- data.frame(grp, df)

# create new df at 6 min level
new.df <- df %>%
group_by(grp) %>%
summarise(new.val = sum(val))





share|improve this answer




























    up vote
    1
    down vote













    Another option with a similar approach



    library(dplyr)

    # original dataframe
    n <- 55940
    df <- data.frame(id = 1:n , val = rnorm(n))

    # new dataframe
    df_new <- df %>%
    group_by(cut(df$id, n/6)) %>%
    summarise(new.val = sum(val))





    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',
      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
      });


      }
      });






      Shah is a new contributor. Be nice, and check out our Code of Conduct.










       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205808%2fadding-rows-in-r-for-large-dataset%23new-answer', 'question_page');
      }
      );

      Post as a guest
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote













      You could try something like this:



      library(dplyr)

      # original df
      df <- data.frame(min = 1:60, val = rnorm(60))

      # create a grouping variable and add to df
      grp <- floor(df$min / 6)
      df <- data.frame(grp, df)

      # create new df at 6 min level
      new.df <- df %>%
      group_by(grp) %>%
      summarise(new.val = sum(val))





      share|improve this answer

























        up vote
        1
        down vote













        You could try something like this:



        library(dplyr)

        # original df
        df <- data.frame(min = 1:60, val = rnorm(60))

        # create a grouping variable and add to df
        grp <- floor(df$min / 6)
        df <- data.frame(grp, df)

        # create new df at 6 min level
        new.df <- df %>%
        group_by(grp) %>%
        summarise(new.val = sum(val))





        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          You could try something like this:



          library(dplyr)

          # original df
          df <- data.frame(min = 1:60, val = rnorm(60))

          # create a grouping variable and add to df
          grp <- floor(df$min / 6)
          df <- data.frame(grp, df)

          # create new df at 6 min level
          new.df <- df %>%
          group_by(grp) %>%
          summarise(new.val = sum(val))





          share|improve this answer












          You could try something like this:



          library(dplyr)

          # original df
          df <- data.frame(min = 1:60, val = rnorm(60))

          # create a grouping variable and add to df
          grp <- floor(df$min / 6)
          df <- data.frame(grp, df)

          # create new df at 6 min level
          new.df <- df %>%
          group_by(grp) %>%
          summarise(new.val = sum(val))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 8 at 10:49









          Cleland

          1356




          1356
























              up vote
              1
              down vote













              Another option with a similar approach



              library(dplyr)

              # original dataframe
              n <- 55940
              df <- data.frame(id = 1:n , val = rnorm(n))

              # new dataframe
              df_new <- df %>%
              group_by(cut(df$id, n/6)) %>%
              summarise(new.val = sum(val))





              share|improve this answer

























                up vote
                1
                down vote













                Another option with a similar approach



                library(dplyr)

                # original dataframe
                n <- 55940
                df <- data.frame(id = 1:n , val = rnorm(n))

                # new dataframe
                df_new <- df %>%
                group_by(cut(df$id, n/6)) %>%
                summarise(new.val = sum(val))





                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Another option with a similar approach



                  library(dplyr)

                  # original dataframe
                  n <- 55940
                  df <- data.frame(id = 1:n , val = rnorm(n))

                  # new dataframe
                  df_new <- df %>%
                  group_by(cut(df$id, n/6)) %>%
                  summarise(new.val = sum(val))





                  share|improve this answer












                  Another option with a similar approach



                  library(dplyr)

                  # original dataframe
                  n <- 55940
                  df <- data.frame(id = 1:n , val = rnorm(n))

                  # new dataframe
                  df_new <- df %>%
                  group_by(cut(df$id, n/6)) %>%
                  summarise(new.val = sum(val))






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 8 at 11:11









                  paoloeusebi

                  36119




                  36119






















                      Shah is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      Shah is a new contributor. Be nice, and check out our Code of Conduct.













                      Shah is a new contributor. Be nice, and check out our Code of Conduct.












                      Shah is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205808%2fadding-rows-in-r-for-large-dataset%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest




















































































                      Popular posts from this blog

                      Schultheiß

                      Verwaltungsgliederung Dänemarks

                      Liste der Kulturdenkmale in Wilsdruff