title: Filter days of week with two different conditions
body: <p>I'm trying to tidy my daily activity data (accelerometer data). I would like to sum and average the repeated days of my data, but only for days that have <code>A2.Working &gt; 6 hours</code>. Another condition is that the day must have completely 24 hours to be included as a valid day. The valid day will contain these 3 variables <code>A1.NonWorking, A2.Working, A4.SleepWeek</code> and their sum will be 24 hours (eg. the data bellow the <code>Weekday 2</code> don't have 24 hours, because the accelerometer was attached on this day (Tuesday). Here is a reproducible example:</p>
  
  <pre><code>df &lt;- tibble(
   LbNr = c(22002,22002,22002,22002,
   22002,22002,22002,22002,22002,22002,22002,22002,22002,
   22002,22002,22002,22002,22002,22002,22002,22002,22002,
   22002,22002,22002,22002),
   Type = c("A2.Working","A1.NonWorking",
  "A4.SleepWeek","A4.SleepWeek","A1.NonWorking","A2.Working",
  "A1.NonWorking","A1.NonWorking","A4.SleepWeek","A1.NonWorking",
  "A2.Working","A1.NonWorking","A4.SleepWeek","A4.SleepWeek",
  "A1.NonWorking","A2.Working","A1.NonWorking","C0.Leisure",
  "C4.SleepWeekend","C0.Leisure","C0.Leisure","C4.SleepWeekend",
  "C0.Leisure","C4.SleepWeekend","A4.SleepWeek","A1.NonWorking"),
  Weekday = c(2,2,2,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,7,1,1),
  Time = c(9.83333,6.05,0.11667,6.83333,1.33333,
  9.83333,6,0.03333,7.2,6.43333,5,5.23333,0.1,6.41667,0.96667,11.01667,
  5.6,0.43333,7.9,15.66667,0.03333,7.91667,15.61667,0.43333,6.33333,0.66667))
  </code></pre>
  
  <p>I tried this code without select specific days:</p>
  
  <pre><code>df %&gt;% 
  group_by(LbNr, Type, Weekday) %&gt;%
  summarise_all(.,sum) %&gt;%
  group_by(LbNr, Weekday) %&gt;%
  filter(any((Time &gt;= 6 &amp; Type == "A2.Working") | Weekday == 6 | Weekday == 7)) %&gt;%
  group_by(LbNr, Type) %&gt;%
  select(-Weekday) %&gt;%
  summarise_all(., mean, na.rm = TRUE)
  </code></pre>
  
  <p>But, when I run the code I get the following:</p>
  
  <pre><code>LbNr   Type             Time
    &lt;dbl&gt; &lt;chr&gt;           &lt;dbl&gt;
  1 22002 A1.NonWorking    6.65
  2 22002 A2.Working      10.2 
  3 22002 A4.SleepWeek     4.46
  4 22002 C0.Leisure      15.9 
  5 22002 C4.SleepWeekend  8.12
  </code></pre>
  
  <p>If I sum the workday (6.65 + 10.20 + 4.46 = 21.31) it gives me the wrong result because it sums the <code>Weekday 2, 3, 4, 5</code> of <code>A1.NonWorking</code> and <code>A4.SleepWeek</code>. </p>
  
  <p>I would like a code that returns this result:</p>
  
  <pre><code>LbNr   Type             Time
    &lt;dbl&gt; &lt;chr&gt;           &lt;dbl&gt;
  1 22002 A1.NonWorking    6.95
  2 22002 A2.Working      10.4 
  3 22002 A4.SleepWeek     6.62
  4 22002 C0.Leisure      15.9 
  5 22002 C4.SleepWeekend  8.12
  </code></pre>
  
  <p>If I sum the workday (6.95 + 10.40 + 6.62 = 23.97, almost 24 hours), I get the correct result with the following code:</p>
  
  <pre><code>df %&gt;%
  group_by(LbNr, Type, Weekday) %&gt;%
  summarise_all(.,sum) %&gt;%
  filter(Weekday %in% c('3':'7')) %&gt;% 
  group_by(LbNr, Weekday) %&gt;%
  filter(any((Time &gt;= 6 &amp; Type == "A2.Working") | Weekday == 6 | Weekday == 7)) %&gt;%
  group_by(LbNr, Type) %&gt;%
  select(-Weekday) %&gt;%
  summarise_all(., mean, na.rm = TRUE)
  </code></pre>
  
  <p>I used <code>filter(Weekday %in% c('3':'7'))</code> for this volunteer because I knew that the <code>Weekday 2</code> didn't have 24 h. I would like code that returns the correct value without the need for a specific filter of days like I did. Only selecting days with 24 h.</p>