0

I have a data.frame that includes meal numbers, glucose time and glucose values. Every meal has nearly 49-50 glucose values (every 5 mins). I need to exclude the meals that have their initial glucose value is higher than 10 mmol/L. I tried to do that with ifelse statement but I couldn't.

    Meal_Number             GluTime   Gluc
1             1 2019-10-26 08:38:00  9.992
2             1 2019-10-26 08:43:00 10.270
3             1 2019-10-26 08:48:00 10.769
4             1 2019-10-26 08:53:00 10.991
5             1 2019-10-26 08:58:00 11.269
6             1 2019-10-26 09:03:00 11.602'
......
47            1 2019-10-26 12:28:00  9.104
48            1 2019-10-26 12:33:00  8.937
49            1 2019-10-26 12:38:00  8.826
50            2 2019-10-26 15:13:00 15.932
51            2 2019-10-26 15:18:00 15.321
52            2 2019-10-26 15:23:00 14.711
53            2 2019-10-26 15:28:00 13.823

For example at above, I should exclude the whole data for the meal number 2. If you help me I will be very appreciated.

  • 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. Use `dput()` to share data so we can copy/paste it into R. Show the code you tried. – MrFlick Apr 25 '23 at 16:01
  • 1
    `df %>% filter(!(head(Gluc, 1) > 10), .by = Meal_Number)` should do it - while the linked duplicate may lend some advice, I dont fully agree this is a duplicate, but a variation of that question which should warrant its own question. – jpsmith Apr 25 '23 at 16:14
  • 1
    Thank you so much jpsmith.. It worked.. I also added another condition in this code: Df1 %>% filter(!(head(Gluc, 1) > 10)&!(head(Gluc, 1) < 3.9), .by = Meal_Number) – user21528954 Apr 25 '23 at 16:39

0 Answers0