Reputation: 125
Example of Constricted Data Table:
I would like to be able to filter out rows of data based on if a particular value exists in another column. The rows I would like to filter out would all have the same "Material" #. In the example I provided, the Material #U83231036 has the value, "ZHLB (ConAgra Semifinished prod)" in one of the two rows in the "Material_Type_Comp" column. I want to be able to extract out the two rows of data related to that Material # because that value exists in the "Material_Type_Comp" column for one of the rows.
What is the best way to go about doing this?
Upvotes: 1
Views: 194
Reputation: 886968
One option is to do a filter
by group
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)")
Upvotes: 1