0

I have a list of protein of fruit fly and its ortholog protein of silkworm, they are in a 2031*2 data frame, now I have another list which is some of the protein presented above and it’s gene name ,how do I add another column in the first data frame, and place the gene name of that protein after it according to the second list. For example

List1:
1  a
2  b
3  c
List2:
A  a
C  c
After opration
1  a  A
2  b  
3  c  C
Sotos
  • 51,121
  • 6
  • 32
  • 66
程劲韬
  • 11
  • 1

1 Answers1

0

just join frames using dplyr

df1 <- data.frame(df1colname1 = 1:3,
                  df1colname2 = c('a','b', 'c'))
df2 <- data.frame(df2colname1 = c('A', 'C'),
                  df2colname2 = c('a', 'c'))

library(dplyr)
df.after.opration <- inner_join(df1, df2, by = c('df1colname2' = 'df2colname2')) 

out

  df1colname1 df1colname2 df2colname1
1           1           a           A
2           3           c           C

if you want to keep all df1 rows use left_join

df.after.opration <- left_join(df1, df2, by = c('df1colname2' = 'df2colname2')) 

out

  df1colname1 df1colname2 df2colname1
1           1           a           A
2           2           b        <NA>
3           3           c           C
dy_by
  • 1,061
  • 1
  • 4
  • 13