How to Use rbind and cbind on Single Dataframe

0 votes

Sorry for framing the question incorrectly. As a beginner, I'm attempting to learn R on my own.

I have a situation where,

t1_df

id   name   address
1     x       india
2     y       usa

t2_df

id   name   address
3     a      india
4     b       usa

Now i tried to add extra column "msg" using data.frame i.e

t1_df <- data.frame(t1_df,msg)
t2_df <- data.frame(t2_df,msg)

t1_df

  id   name   address   msg
  1     x       india   hi
  2     y       usa     hello

t2_df

id   name   address   msg
3     a      india     go
4     b       usa      bye

when i tried to do rbind it gives error as col names are not matching because both df's having different col names

When i tried to cbind on both df's into single dataframe is t, it included all the columns from both df's i.e

colnames(t)

id   name   address   t1_msg   id   name   address   t2_msg

But i would like to get the dataframe as

id   name   address   t1_msg   t2_msg
  1     x       india   hi       NA
  2     y       usa     hello    NA
  3     a      india     NA      go
  4     b       usa      NA      bye

How do I obtain the output that I described above?

Help me out, please.

Jul 22 in Data Analytics by avinash
• 1,840 points
18 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Data Analytics

0 votes
1 answer
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 455 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 14, 2018 in Data Analytics by Sahiti
• 6,380 points
4,425 views
0 votes
4 answers

How to change font size of text and axes on R plots ?

To change the font size of text ...READ MORE

answered Dec 16, 2020 in Data Analytics by Gitika
• 65,870 points
55,863 views
0 votes
1 answer

How to add regression line equation and R2 on graph?

Below is one solution: # GET EQUATION AND ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,240 points
5,928 views
0 votes
1 answer

R language has several packages for solving a problem. How do you make a decision on which one is the best to use?

CRAN package ecosystem has more than 6000 ...READ MORE

answered Jun 5, 2018 in Data Analytics by zombie
• 3,790 points
590 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
437 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
479 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
4,351 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
503 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP