[英]How to eliminate rows in a dataframe based column names in another dataframe
I have two dataframes.我有两个数据框。 DF1 has all recorded species names in rows and DF2 has a subset of those species in columns. DF1 在行中包含所有记录的物种名称,而 DF2 在列中包含这些物种的子集。 I need both dataframes to match so I need to eliminate rows in DF1 which do not correspond to columns in DF2.我需要两个数据框匹配,所以我需要消除 DF1 中与 DF2 中的列不对应的行。
I tried using %in% but I can't work out how to use two daatframes in the same formula.我尝试使用 %in% 但我不知道如何在同一个公式中使用两个 daatframes。
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 . . .
也许可以帮助你这个R base
代码:
DF1_new <- DF1[DF1$species %in% colnames(DF2), ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.