![](/img/trans.png)
[英]How to delete rows in a column dataframe based on the column in another dataframe in R?
[英]How to eliminate rows in a dataframe based column names in another dataframe
我有兩個數據框。 DF1 在行中包含所有記錄的物種名稱,而 DF2 在列中包含這些物種的子集。 我需要兩個數據框匹配,所以我需要消除 DF1 中與 DF2 中的列不對應的行。
我嘗試使用 %in% 但我不知道如何在同一個公式中使用兩個 daatframes。
我希望我的問題足夠清楚!
任何幫助將不勝感激!
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.