Sorry hold[list] generates error.
• 0 views
•
link
Hi Guys,
Is there a way to reorder the column of two tables, table1 and table2, according to the column names in the list (in the same order) and merge them into one table result.table.
list<-c("MAPK", "BCL2", "ALB", "MAPKK", "MEKK", "JUNK", "STR", "BRCA1")
table1
MAPK MAPKK MEKK JUNK STR
5 5 6 7 9
3 4 5 7 8
table2
BCL2 ALB BRCA1
4 4 3
4 4 3
result.table
MAPK BCL2 ALB MAPKK MEKK JUNK STR BRCA1
5 4 4 5 6 7 9 3
3 4 4 4 5 7 8 3
Thank you!
#combine the tables
hold <- cbind(table1, table2)
#order by 'list'
result.table <- hold[ , list]
This assumes that table1 and table2 are data frames with column names as indicated in 'list.'
Log in to answer this question.