title: Summarise using multiple functions with dplyr across()
body: <p>I have data where an id variable should identify a unique observation. However, some ids are repeated. I want to get an idea of which measurements are driving this repetition by grouping by id and then calculating the proportion of inconsistent responses for each variable.</p>
  <p>Below is an example of what I mean:</p>
  <pre><code>require(tidyverse)
  
  df &lt;- tibble(id = c(1,1,2,3,4,4,4),
               col1 = c('a','a','b','b','c','c','c'), # perfectly consistent
               col2 = c('a','b','b','b','c','c','c'), # id 1 is inconsistent - proportion inconsistent = 0.25
               col3 = c('a','a','b','b','a','b','c'), # id 4 is inconsistent - proportion inconsistent = 0.25
               col4 = c('a','b','b','b','b','b','c') # id 1 and 4 are inconsistent - proportion inconsistent = 0.5
               )
  </code></pre>
  <p>I can test for inconsistent responses within ids by using group_by(), across(), and n_distinct() as per the below:</p>
  <pre><code># count the number of distinct responses for each id in each column
  # if the value is equal to 1, it means that all responses were consistent
  df &lt;- df %&gt;% 
    group_by(id) %&gt;% 
    mutate(across(.cols = c(col1:col4), ~n_distinct(.), .names = '{.col}_distinct')) %&gt;% 
    ungroup()
  </code></pre>
  <p>For simplicity I can now take one row for each id:</p>
  <pre><code># take one row for each test (so we aren't counting duplicates twice)
  df &lt;- distinct(df, across(c(id, contains('distinct'))))
  </code></pre>
  <p>Now I would like to calculate the proportion of ids that contained an inconsistent response for each variable. I would like to do something like the following:</p>
  <pre><code>consistency &lt;- df %&gt;% 
    summarise(across(contains('distinct'), ~sum(.&gt;1) / n(.)))
  </code></pre>
  <p>But this gives the following error, which I am having trouble interpreting:</p>
  <pre><code>Error: Problem with `summarise()` input `..1`.
  x unused argument (.)
  ℹ Input `..1` is `across(contains(&quot;distinct&quot;), ~sum(. &gt; 1)/n(.))`.
  </code></pre>
  <p>I can get the answer I want by doing the following:</p>
  <pre><code># calculate consistency for each column by finding the number of distinct values greater 
  # than 1 and dividing by total rows
  # first get the number of distinct values
  n_inconsistent &lt;- df %&gt;% 
    summarise(across(.cols = contains('distinct'), ~sum(.&gt;1)))
  
  # next get the number of rows
  n_total &lt;- nrow(df)
  
  # calculate the proportion of tests that have more than one value for each column
  consistency &lt;- n_inconsistent %&gt;% 
    mutate(across(contains('distinct'), ~./n_total))
  </code></pre>
  <p>But this involves intermediate variables and feels inelegant.</p>