How to conneted same dataframe column? [closed]










-1














i want connect column in same dataframe.



for example,



# I have data type is below 
region=c("A","B","C")
Q1=c("ads","qwer","zxcv")
Q2=c("poi","lkj","mnb")
temp=data.frame(region, Q1, Q2)
### i want chaged below
region1=c("A","B","C")
Q=c("ads,poi","qwer,lkj","zxcv,mnb")
temp2=data.frame(region1, Q)


How to do it... ?










share|improve this question













closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















    -1














    i want connect column in same dataframe.



    for example,



    # I have data type is below 
    region=c("A","B","C")
    Q1=c("ads","qwer","zxcv")
    Q2=c("poi","lkj","mnb")
    temp=data.frame(region, Q1, Q2)
    ### i want chaged below
    region1=c("A","B","C")
    Q=c("ads,poi","qwer,lkj","zxcv,mnb")
    temp2=data.frame(region1, Q)


    How to do it... ?










    share|improve this question













    closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11


    Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

















      -1












      -1








      -1







      i want connect column in same dataframe.



      for example,



      # I have data type is below 
      region=c("A","B","C")
      Q1=c("ads","qwer","zxcv")
      Q2=c("poi","lkj","mnb")
      temp=data.frame(region, Q1, Q2)
      ### i want chaged below
      region1=c("A","B","C")
      Q=c("ads,poi","qwer,lkj","zxcv,mnb")
      temp2=data.frame(region1, Q)


      How to do it... ?










      share|improve this question













      i want connect column in same dataframe.



      for example,



      # I have data type is below 
      region=c("A","B","C")
      Q1=c("ads","qwer","zxcv")
      Q2=c("poi","lkj","mnb")
      temp=data.frame(region, Q1, Q2)
      ### i want chaged below
      region1=c("A","B","C")
      Q=c("ads,poi","qwer,lkj","zxcv,mnb")
      temp2=data.frame(region1, Q)


      How to do it... ?







      r dataframe connect






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 7:33









      Sung min YangSung min Yang

      174




      174




      closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






      closed as unclear what you're asking by Wimpel, MLavoie, Umair, greg-449, Rob Nov 13 '18 at 16:11


      Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
























          3 Answers
          3






          active

          oldest

          votes


















          1














          temp$Q <- apply(temp[-1], 1, toString)
          temp[c("Q1", "Q2")] <- NULL
          temp
          region Q
          1 A ads, poi
          2 B qwer, lkj
          3 C zxcv, mnb





          share|improve this answer




























            1














            Using base R you can do:



            temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
            temp <- temp[,c("region", "Q")]
            temp

            region Q
            1 A ads,poi
            2 B qwer,lkj
            3 C zxcv,mnb





            share|improve this answer




























              0














              This would be a solution using the mutate function from the dplyr package to create the new column Q by using paste0 to concatenate the columns Q1 and Q2. In the end I just removed the columns Q1 and Q2 by using select with -:



              library(dplyr)
              temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)





              share|improve this answer




















              • oh thank you : )
                – Sung min Yang
                Nov 13 '18 at 7:46

















              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              temp$Q <- apply(temp[-1], 1, toString)
              temp[c("Q1", "Q2")] <- NULL
              temp
              region Q
              1 A ads, poi
              2 B qwer, lkj
              3 C zxcv, mnb





              share|improve this answer

























                1














                temp$Q <- apply(temp[-1], 1, toString)
                temp[c("Q1", "Q2")] <- NULL
                temp
                region Q
                1 A ads, poi
                2 B qwer, lkj
                3 C zxcv, mnb





                share|improve this answer























                  1












                  1








                  1






                  temp$Q <- apply(temp[-1], 1, toString)
                  temp[c("Q1", "Q2")] <- NULL
                  temp
                  region Q
                  1 A ads, poi
                  2 B qwer, lkj
                  3 C zxcv, mnb





                  share|improve this answer












                  temp$Q <- apply(temp[-1], 1, toString)
                  temp[c("Q1", "Q2")] <- NULL
                  temp
                  region Q
                  1 A ads, poi
                  2 B qwer, lkj
                  3 C zxcv, mnb






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 8:16









                  snoramsnoram

                  6,399831




                  6,399831























                      1














                      Using base R you can do:



                      temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
                      temp <- temp[,c("region", "Q")]
                      temp

                      region Q
                      1 A ads,poi
                      2 B qwer,lkj
                      3 C zxcv,mnb





                      share|improve this answer

























                        1














                        Using base R you can do:



                        temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
                        temp <- temp[,c("region", "Q")]
                        temp

                        region Q
                        1 A ads,poi
                        2 B qwer,lkj
                        3 C zxcv,mnb





                        share|improve this answer























                          1












                          1








                          1






                          Using base R you can do:



                          temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
                          temp <- temp[,c("region", "Q")]
                          temp

                          region Q
                          1 A ads,poi
                          2 B qwer,lkj
                          3 C zxcv,mnb





                          share|improve this answer












                          Using base R you can do:



                          temp$Q <- paste(temp$Q1, temp$Q2, sep=",")
                          temp <- temp[,c("region", "Q")]
                          temp

                          region Q
                          1 A ads,poi
                          2 B qwer,lkj
                          3 C zxcv,mnb






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 13 '18 at 7:36









                          alex_555alex_555

                          6661315




                          6661315





















                              0














                              This would be a solution using the mutate function from the dplyr package to create the new column Q by using paste0 to concatenate the columns Q1 and Q2. In the end I just removed the columns Q1 and Q2 by using select with -:



                              library(dplyr)
                              temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)





                              share|improve this answer




















                              • oh thank you : )
                                – Sung min Yang
                                Nov 13 '18 at 7:46















                              0














                              This would be a solution using the mutate function from the dplyr package to create the new column Q by using paste0 to concatenate the columns Q1 and Q2. In the end I just removed the columns Q1 and Q2 by using select with -:



                              library(dplyr)
                              temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)





                              share|improve this answer




















                              • oh thank you : )
                                – Sung min Yang
                                Nov 13 '18 at 7:46













                              0












                              0








                              0






                              This would be a solution using the mutate function from the dplyr package to create the new column Q by using paste0 to concatenate the columns Q1 and Q2. In the end I just removed the columns Q1 and Q2 by using select with -:



                              library(dplyr)
                              temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)





                              share|improve this answer












                              This would be a solution using the mutate function from the dplyr package to create the new column Q by using paste0 to concatenate the columns Q1 and Q2. In the end I just removed the columns Q1 and Q2 by using select with -:



                              library(dplyr)
                              temp %>% mutate(Q = paste0(Q1,", ",Q2)) %>% select(-Q1,-Q2)






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 13 '18 at 7:36









                              FloSchmoFloSchmo

                              4486




                              4486











                              • oh thank you : )
                                – Sung min Yang
                                Nov 13 '18 at 7:46
















                              • oh thank you : )
                                – Sung min Yang
                                Nov 13 '18 at 7:46















                              oh thank you : )
                              – Sung min Yang
                              Nov 13 '18 at 7:46




                              oh thank you : )
                              – Sung min Yang
                              Nov 13 '18 at 7:46



                              Popular posts from this blog

                              Top Tejano songwriter Luis Silva dead of heart attack at 64

                              ReactJS Fetched API data displays live - need Data displayed static

                              政党