0

I have two dataframes which only slightly differ in column names: Call the first one df1:

ID   azC   deC   PdC
101  2     3      2
102  3     1      1
103  0     1      2
104  0     3      0

Call the second df2:

ID   azP  deP    PdP
203   3   2      1
204   2   2      3
266   0   3      0
277   3   3      1

So, ID is the same in both dataframes. The column names only differ by the ending. df1 has C at the end and df2 has P. The names are the same otherwise.

When I try this method:

df_all <- merge(df1, df2, by=c('ID'))

I get dropped values. I want to retain all the values such that the data endings of P come after the endings of C:

ID  azC   deC   PdC   azP   deP  azP

Is there a way to do this in R? Or is it easier to do it with completely raw data before organizing it in a df?

AcidCatfish
  • 192
  • 8

0 Answers0