1

Example of Constricted Data Table:

img

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?

camille
  • 16,432
  • 18
  • 38
  • 60
Ifad Noor
  • 105
  • 1
  • 1
  • 7
  • 1
    You should provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – M-- Nov 21 '19 at 19:02
  • 1
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a loadable sample of data (not a picture of it), all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Nov 21 '19 at 19:02

1 Answers1

1

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)")
akrun
  • 874,273
  • 37
  • 540
  • 662