0
d1 %>%
       filter(WEIGHT2 != 7777 & WEIGHT2 != 9999 & HAVARTH3 == 2 | HAVARTH3 == 1) %>%
       group_by(HAVARTH3) %>%
       mutate(kb_LB = ifelse(MENTHLTH > 8999 & MENTHLTH < 10000, "kb", "lbs")) %>%
       select(WEIGHT2, kb_LB)

when I look at the results i see records with WEIGHT2 of 9999. I think my filter statement is throwing it off but not sure.

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
Evan Day
  • 23
  • 4
  • 6
    In any programming language, R and beyond, whenever you combine `and` and `or` conditions, always use parentheses between conditions. – Parfait Apr 11 '22 at 21:22
  • 1
    You are combing AND or OR statements and the order of operations from the `?Syntax` help page says that all the ANDs happen first, then the ORs, just like multiplication happens before addition. So if HAVARTH3 == 1 is TRUE, then none of the WEIGHT2 checks matter. In the future 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 Apr 11 '22 at 21:51
  • there is no way to have all conditions checked? – Evan Day Apr 12 '22 at 02:22

0 Answers0