1
votes

I have two dataframes. DF1 has all recorded species names in rows and DF2 has a subset of those species in columns. I need both dataframes to match so I need to eliminate rows in DF1 which do not correspond to columns in DF2.

I tried using %in% but I can't work out how to use two daatframes in the same formula.

I hope my question is clear enough!

Any help would be greatly appreciated!

DF1
species  V1 V2
a
b
c
d
e

DF2

   a b d 
r1 . . .
r2 . . .
r3 . . . 
1

1 Answers

1
votes

Maybe helps you this R base code:

DF1_new <- DF1[DF1$species %in% colnames(DF2), ]