简体   繁体   English

如何消除另一个数据框中基于列名的数据框中的行

[英]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.

相关问题 如何根据R中另一个dataframe中的列删除列dataframe中的行? - How to delete rows in a column dataframe based on the column in another dataframe in R? 如何通过根据另一个数据帧的行名的顺序映射一个数据帧的列名来对 R 中的数据帧进行排序? - How to sort a dataframe in R by mapping column names of one dataframe based on the order of row names of another dataframe? 如何根据另一个 dataframe 的列中的值对列名进行排序? - How to sort column names based on values in a column of another dataframe? 如何基于一个数据框中的列的值和R中另一个数据框的列标题名称有条件地创建新列 - how to conditionally create new column based on the values of a column in one dataframe and the column header names of another dataframe in R 根据另一个数据框中的值有条件地替换数据框中的列名 - Conditionally replace column names in a dataframe based on values in another dataframe 根据 dplyr 与另一个 dataframe 的匹配更改 dataframe 中的列名 - Change column names in dataframe based on matching to another dataframe by dplyr 如何创建仅包含来自另一个数据框的某些行且具有列名的数据框? - How do I create a dataframe with only some rows from another dataframe, with column names? 根据列名称向数据框添加行,并将NA添加至空列 - Adding rows to a dataframe based on column names and add NA to empty columns 如何根据列中的值选择数据框中的行 - How to select rows in a dataframe based on values in a column 基于另一个列名部分匹配的 dataframe 索引 - Index into one dataframe based on another with partial-match of column names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM