|
Hi Freinds,
I have two data frames X,Y. I want to append both the data frames into one, along with the columns names from both the data frames (it should look like Z). X: Summary G Y R Acc 12 12 13 Bcc 11 14 15 Ccc 13 15 16 Y: Summary G Y R Acc 10 11 12 Bcc 13 12 11 Ccc 11 16 20 Result ---------- Z: Summary G Y R Acc 12 12 13 Bcc 11 14 15 Ccc 13 15 16 Summary G Y R Acc 10 11 12 Bcc 13 12 11 Ccc 11 16 20 Can anyone help me on this. Thanks in Advance. Thanks, Namit. |
|
This post has NOT been accepted by the mailing list yet.
Hello,
Try this: X<-read.table(text=" Summary G Y R Acc 12 12 13 Bcc 11 14 15 Ccc 13 15 16 ",sep="",header=TRUE,stringsAsFactors=FALSE) Y<-read.table(text=" Summary G Y R Acc 10 11 12 Bcc 13 12 11 Ccc 11 16 20 ",sep="",header=TRUE,stringsAsFactors=FALSE) rbind(X,colnames(Y),Y) Summary G Y R 1 Acc 12 12 13 2 Bcc 11 14 15 3 Ccc 13 15 16 4 Summary G Y R 5 Acc 10 11 12 6 Bcc 13 12 11 7 Ccc 11 16 20 A.K. |
|
In reply to this post by namit
You can't have two sets of colnames on a single data.frame
What are you trying to do (big picture wise)? Michael On Jul 28, 2012, at 12:56 PM, namit <[hidden email]> wrote: > Hi Freinds, > > I have two data frames X,Y. I want to append both the data frames into one, > along with the columns names from both the data frames (it should look like > Z). > > X: > Summary G Y R > Acc 12 12 13 > Bcc 11 14 15 > Ccc 13 15 16 > > Y: > Summary G Y R > Acc 10 11 12 > Bcc 13 12 11 > Ccc 11 16 20 > > > > Result > ---------- > Z: > > Summary G Y R > Acc 12 12 13 > Bcc 11 14 15 > Ccc 13 15 16 > Summary G Y R > Acc 10 11 12 > Bcc 13 12 11 > Ccc 11 16 20 > > > Can anyone help me on this. > > Thanks in Advance. > > Thanks, > Namit. > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Appending-the-Column-names-tp4638207.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by namit
You cannot have two sets of column names in a data.frame
You can do this rbind(X, Y) Summary G Y R 1 Acc 12 12 13 2 Bcc 11 14 15 3 Ccc 13 15 16 4 Acc 10 11 12 5 Bcc 13 12 11 6 Ccc 11 16 20 John Kane Kingston ON Canada > -----Original Message----- > From: [hidden email] > Sent: Sat, 28 Jul 2012 10:56:13 -0700 (PDT) > To: [hidden email] > Subject: [R] Appending the Column names > > Hi Freinds, > > I have two data frames X,Y. I want to append both the data frames into > one, > along with the columns names from both the data frames (it should look > like > Z). > > X: > Summary G Y R > Acc 12 12 13 > Bcc 11 14 15 > Ccc 13 15 16 > > Y: > Summary G Y R > Acc 10 11 12 > Bcc 13 12 11 > Ccc 11 16 20 > > > > Result > ---------- > Z: > > Summary G Y R > Acc 12 12 13 > Bcc 11 14 15 > Ccc 13 15 16 > Summary G Y R > Acc 10 11 12 > Bcc 13 12 11 > Ccc 11 16 20 > > > Can anyone help me on this. > > Thanks in Advance. > > Thanks, > Namit. > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Appending-the-Column-names-tp4638207.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
| Powered by Nabble | Edit this page |
