Hi Guys,
I have two data frames with thousands of columns. The dummy example looks like df1 and df2 below. All the columns names in df2 are in df1. Now, I want these two data frames to combined together in the order where the columns with the same columns names are together as shown in result. Thank you.
df1 <- data.frame(C1=c("A","H","C"),C2=c("0","0","0"), C3=c("A","C","D"),C4=c("A","V","G"))
df1
C1 C2 C3 C4
1 A 0 A A
2 H 0 C V
3 C 0 D G
df2 <- data.frame(C1=c("A","B","C"),C3=c("G","G","G"))
df2
C1 C3
1 A G
2 B G
3 C G
Result
C1 C1 C2 C3 C3 C4
1 A A 0 A G A
2 H B 0 C G V
3 C C 0 D G G
MAPK, you have asked a lot of R programming questions recently (examples of those that need to join/extract/compare multiple data tables):
You're welcome to ask R related questions here on biostars. However, I recommend to invest some time into learning R data manipulation tools:
This should help you to solve problems yourself. Also, you can try to ask R related questions on stackoverflow.com (most of your questions aren't bioinformatics specific, they are just general data structure manipulation problems). Further, it would be nice if you accept answers to your previous questions (if they helped you).