title: Group by a column and then automatically count over multiple columns starting with the same alphabet
body: <p>I am trying to do a simple <code>counts</code> action combined with the <code>group_by</code> functionality.</p>
  <p>For example, if the <code>df</code> is as below:</p>
  <pre><code>Task   q1  q2
  Alpha  1   NA
  Beta   NA  NA
  Alpha  4   2
  Alpha  5   NA
  Beta   2   2
  Gamma  NA  3
  </code></pre>
  <p>I want to have the following output</p>
  <pre><code>Task   q1   q2
  Alpha  3    1 
  Beta   1    1 
  Gamma  0    1 
  </code></pre>
  <h3>Requirement 1:</h3>
  <p>Overall, I want to count how many times the entries correspond to non-missing values (anything from 0-5 in this example). I am not interested in what the values are, I am only interested in how many times they are reported - corresponding to each of the tasks.</p>
  <p>I can do this using the <code>sqldf</code> as below:</p>
  <pre><code>sqldf('SELECT Task, count(q1), count(q2)
  FROM df
  GROUP BY Task')
  </code></pre>
  <p>I can also do this using the <code>dplyr</code> package:</p>
  <pre><code>df %&gt;%  
    group_by(Task) %&gt;% 
    summarise(q1 = sum(!is.na(q1)),
              q2 = sum(!is.na(q2)))
  </code></pre>
  <p>But I want to know if there is an automated way of doing this, for example when I have a variable number of measures, sometimes <code>q1:q3</code> and sometimes they may be <code>q1:q10</code>. Something like <code>paste0(&quot;q&quot;, 1:n)</code>. But I am having difficulty incorporating this into my code.</p>
  <h3>Requirement 2:</h3>
  <p>Later on, I also want to calculate the percentage of occurrence of each of the measures <code>q</code> for each of the tasks <code>alpha, beta, gamma</code>.</p>
  <p>Any help would be greatly appreciated.</p>
  <p>I have seen other posts but they have not been useful to me, probably because of my lack of ability in coding using the <code>dplyr</code> package. For example,</p>
  <p><a href="https://stackoverflow.com/questions/41306629/r-group-by-multiple-columns-and-count">r: group by multiple columns and count</a>,</p>
  <p><a href="https://stackoverflow.com/questions/51086816/how-do-i-get-count-from-multiple-columns-in-r">How do I get count from multiple columns in R?</a></p>
  <p>and</p>
  <p><a href="https://stackoverflow.com/questions/61265951/count-occurance-of-multiple-columns-by-group-in-r">Count occurance of multiple columns by group in R</a></p>