I have an empty dataframe which I want to fill using another dataframeRecalculate each point in dataframe with lapply/sapplyCreating an empty Pandas DataFrame, then filling it?How to check whether a pandas DataFrame is empty?R: Creating a data frame from list with missing values.Fill pandas dataframe with specific values from jsonHow to increment values in a matrix using 3 for loops in RRemove columns from dataframe where ALL values are NA, NULL or emptyHow to subset variables which have NA in the values?r - Filtering by Rank in a df with with NAs - Not workingWhat is wrong with my pattern matching and replacement function

Enumerate Derangements

CRT Oscilloscope - part of the plot is missing

Is it cheaper to drop cargo than to land it?

What is the most remote airport from the center of the city it supposedly serves?

Sed Usage to update GRUB file

Is Cola "probably the best-known" Latin word in the world? If not, which might it be?

What happens to matryoshka Mordenkainen's Magnificent Mansions?

Returning the outputs of a nested structure

Is it possible to set that path of the scp command to use by OpenSSH sshd daemon?

What are the differences between credential stuffing and password spraying?

Pressure to defend the relevance of one's area of mathematics

Reconstruct a matrix from its traces

Should my Json storage handle exceptions?

I caught several of my students plagiarizing. Could it be my fault as a teacher?

How do I tell my manager that his code review comment is wrong?

LightGBM results differently depending on the order of the data

Casual versus formal jacket

To customize a predefined symbol with different colors only with pdfLaTeX

when are two topological spaces homeomorphic?

Would glacier 'trees' be plausible?

Which industry am I working in? Software development or financial services?

Why do computer-science majors learn calculus?

How could a planet have most of its water in the atmosphere?

Do I have to make someone coauthor if he/she solves a problem in StackExchange, asked by myself, which is later used in my paper?



I have an empty dataframe which I want to fill using another dataframe


Recalculate each point in dataframe with lapply/sapplyCreating an empty Pandas DataFrame, then filling it?How to check whether a pandas DataFrame is empty?R: Creating a data frame from list with missing values.Fill pandas dataframe with specific values from jsonHow to increment values in a matrix using 3 for loops in RRemove columns from dataframe where ALL values are NA, NULL or emptyHow to subset variables which have NA in the values?r - Filtering by Rank in a df with with NAs - Not workingWhat is wrong with my pattern matching and replacement function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have an empty dataframe which is my template



temp <- data.frame(matrix(ncol=3))
colnames(temp) <- c("variable", "group", "bin")



And another dataframe which has the details of these:



info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))



I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.



When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
replacement has 6 rows, data has 1










share|improve this question




























    1















    I have an empty dataframe which is my template



    temp <- data.frame(matrix(ncol=3))
    colnames(temp) <- c("variable", "group", "bin")



    And another dataframe which has the details of these:



    info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))



    I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.



    When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
    replacement has 6 rows, data has 1










    share|improve this question
























      1












      1








      1








      I have an empty dataframe which is my template



      temp <- data.frame(matrix(ncol=3))
      colnames(temp) <- c("variable", "group", "bin")



      And another dataframe which has the details of these:



      info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))



      I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.



      When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
      replacement has 6 rows, data has 1










      share|improve this question














      I have an empty dataframe which is my template



      temp <- data.frame(matrix(ncol=3))
      colnames(temp) <- c("variable", "group", "bin")



      And another dataframe which has the details of these:



      info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))



      I want the variable name to be "group_abc", and group to have values of group_abc and bin to have values of bin_abc.



      When I was trying to use the values from the dataframe, it gives me an error saying: Error in$<-.data.frame(tmp, group, value = c("0-699", "700-750", :
      replacement has 6 rows, data has 1







      r dataframe multiple-columns is-empty






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 21:05









      Bruce WayneBruce Wayne

      11212




      11212






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:



           info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
          temp <- setNames( info, c("group", "bin"))

          > temp
          group bin
          1 1 0-700
          2 2 700-750
          3 2 750-800
          4 3 800-850
          5 3 850-900
          6 3 900-950


          If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.






          share|improve this answer






























            0














            You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.



            info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))

            temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
            colnames(temp) <- c("variable", "group", "bin")

            temp$group <- info$group_abc
            temp$bin <- info$bin_abc





            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%2f55307757%2fi-have-an-empty-dataframe-which-i-want-to-fill-using-another-dataframe%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














              Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:



               info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
              temp <- setNames( info, c("group", "bin"))

              > temp
              group bin
              1 1 0-700
              2 2 700-750
              3 2 750-800
              4 3 800-850
              5 3 850-900
              6 3 900-950


              If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.






              share|improve this answer



























                0














                Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:



                 info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
                temp <- setNames( info, c("group", "bin"))

                > temp
                group bin
                1 1 0-700
                2 2 700-750
                3 2 750-800
                4 3 800-850
                5 3 850-900
                6 3 900-950


                If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.






                share|improve this answer

























                  0












                  0








                  0







                  Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:



                   info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
                  temp <- setNames( info, c("group", "bin"))

                  > temp
                  group bin
                  1 1 0-700
                  2 2 700-750
                  3 2 750-800
                  4 3 800-850
                  5 3 850-900
                  6 3 900-950


                  If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.






                  share|improve this answer













                  Just assign (value of) the existing dataframe to the new name but change the column names which can be done in one easy step:



                   info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))
                  temp <- setNames( info, c("group", "bin"))

                  > temp
                  group bin
                  1 1 0-700
                  2 2 700-750
                  3 2 750-800
                  4 3 800-850
                  5 3 850-900
                  6 3 900-950


                  If you had wanted only a portion of the existing dataframe to get duplicated, you could have selected either rows or columns or both using "[" on the info argument with the setNames call.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 22 at 22:46









                  42-42-

                  217k15270406




                  217k15270406























                      0














                      You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.



                      info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))

                      temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
                      colnames(temp) <- c("variable", "group", "bin")

                      temp$group <- info$group_abc
                      temp$bin <- info$bin_abc





                      share|improve this answer



























                        0














                        You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.



                        info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))

                        temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
                        colnames(temp) <- c("variable", "group", "bin")

                        temp$group <- info$group_abc
                        temp$bin <- info$bin_abc





                        share|improve this answer

























                          0












                          0








                          0







                          You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.



                          info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))

                          temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
                          colnames(temp) <- c("variable", "group", "bin")

                          temp$group <- info$group_abc
                          temp$bin <- info$bin_abc





                          share|improve this answer













                          You could resolve this by setting up the temp dataframe to have the correct number of rows as well as the correct number of columns when being initialized.



                          info <- data.frame(group_abc = c("1", "2", "2", "3", "3", "3"), bin_abc = c("0-700", "700-750", "750-800", "800-850", "850-900", "900-950"))

                          temp <- data.frame(matrix(ncol=3, nrow = nrow(info)))
                          colnames(temp) <- c("variable", "group", "bin")

                          temp$group <- info$group_abc
                          temp$bin <- info$bin_abc






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 22 at 21:13









                          Emily KotheEmily Kothe

                          461216




                          461216



























                              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%2f55307757%2fi-have-an-empty-dataframe-which-i-want-to-fill-using-another-dataframe%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

                              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

                              용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                              155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해