![](/img/trans.png)
[英]Using Filter or If Else to filter an indicator based on the value in another column in R
[英]Filter a chunk of rows based on a specific value in another column in R
受限数据表示例:
我希望能够根据另一列中是否存在特定值来过滤掉数据行。 我要过滤掉的行都将具有相同的“材料”#。 在我提供的示例中,材料 #U83231036 在“Material_Type_Comp”列的两行之一中具有值“ZHLB (ConAgra Semifinished prod)”。 我希望能够提取与该材料# 相关的两行数据,因为该值存在于其中一行的“Material_Type_Comp”列中。
go 关于这样做的最佳方法是什么?
一种选择是按组进行filter
library(dplyr)
df1 %>%
group_by(Material) %>%
filter("ZHLB (ConAgra Semifinished prod)" %in% Material_Type_Comp)
#or use any with `==`
#filter(any(Material_Type_Comp == "ZHLB (ConAgra Semifinished prod)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.