Hi R user, I could not combine two tables. Would any one help me on how I can combine with following example tables?> T1X Y Z XX A 1 5 9 13 B 2 6 10 14 C 3 7 11 15 D 4 8 12 16> T2X Y XX a 1 4 7 b 2 5 8 c 3 6 9 I want to get the following table cT X Y XX A 1 5 13 B 2 6 14 C 3 7 15 D 4 8 16 A1 1 4 7 B1 2 5 8 C1 3 6 9 Thanks for your help. Thanks, Kristi == [[alternative HTML version deleted]]
David Winsemius
2012-May-10 01:47 UTC
[R] Combine two tables by row with different columns
On May 9, 2012, at 9:21 PM, Kristi Glover wrote:> > Hi R user, > I could not combine two tables. Would any one help me on how I can > combine with following example tables?You do realize that tables in R are not dataframes. They are a type of matrix.> >> T1 > X Y Z XX > A 1 5 9 13 > B 2 6 10 14 > C 3 7 11 15 > D 4 8 12 16 > >> T2 > X Y XX > a 1 4 7 > b 2 5 8 > c 3 6 9 > > I want to get the following table > cT > X Y XX > A 1 5 13 > B 2 6 14 > C 3 7 15 > D 4 8 16 > A1 1 4 7 > B1 2 5 8 > C1 3 6 9Assuming you will accept the rownames as they stand, then try this: cT <- cbind(T1,T2) # works for table, matrices, and dataframes> > [[alternative HTML version deleted]]Plain text, please. -- David Winsemius, MD West Hartford, CT
Hello, Try this T1 <- read.table(text=" X Y Z XX A 1 5 9 13 B 2 6 10 14 C 3 7 11 15 D 4 8 12 16 ", header=TRUE) T2 <- read.table(text=" X Y XX a 1 4 7 b 2 5 8 c 3 6 9 ", header=TRUE) cT <- read.table(text=" X Y XX A 1 5 13 B 2 6 14 C 3 7 15 D 4 8 16 A1 1 4 7 B1 2 5 8 C1 3 6 9 ", header=TRUE) T1; T2; cT (Test <- rbind(T1[, colnames(T2)], T2)) # rownames are different, 'Test' has rownames from T2 all.equal(cT, Test) Hope this helps, Rui Barradas Kristi Glover wrote> > Hi R user, > I could not combine two tables. Would any one help me on how I can combine > with following example tables? > >> T1 > X Y Z XX > A 1 5 9 13 > B 2 6 10 14 > C 3 7 11 15 > D 4 8 12 16 > >> T2 > X Y XX > a 1 4 7 > b 2 5 8 > c 3 6 9 > > I want to get the following table > cT > X Y XX > A 1 5 13 > > B 2 6 14 > > C 3 7 15 > D 4 8 16 > A1 1 4 7 > > B1 2 5 8 > > C1 3 6 9 > > Thanks for your help. > Thanks, > Kristi > ==> > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@ 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. >-- View this message in context: http://r.789695.n4.nabble.com/Combine-two-tables-by-row-with-different-columns-tp4622276p4622321.html Sent from the R help mailing list archive at Nabble.com.