0

I would like to create a new dichotomous variable column (1/0; Yes/No) based on if anyone within a household (marked by a household ID number -- unique to each HOUSEHOLD) has indicated 1 or Yes for a different column?

How would I go about doing this? Happy to clarify.

I am able to do mutate a new column based off of the individuals but not on the household level.

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 3
    It would be helpful to see some example data. See [here](https://stackoverflow.com/questions/49994249/example-of-using-dput). Rather than `mutate` you can `group_by(household) |> mutate(var = if_else(any(other_column == 1), 1, 0` or if you wanted summarized data at household level `group_by(household) |> summarize(var = if_else(other_column == 1, 1, 0))`. – Will Oldham Nov 08 '22 at 19:43
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 08 '22 at 19:46

0 Answers0