title: Expss table with row_percentages and count for nested groups
body: <p>Using the expss package, I'm trying to create a table with nested rows and columns.
  Let's say I have a df of the following structure:
  Each observation refers to a participant who either sits in group A or B.
  The participants answer one or more of 4 items which they can (partially) pass or fail.
  In addition, there are different trials.</p>
  <p>Here some dummy data:</p>
  <pre><code>set.seed(321)
  test &lt;- tibble(
    trial  = rep(c(&quot;Trial_A&quot;, &quot;Trial_B&quot;), each = 6),
    group  = rep(c(&quot;A&quot;, &quot;B&quot;), each = 6),
    result = rep(c(&quot;Fail&quot;, &quot;Pass&quot;, &quot;Partial Pass&quot;), times = 4),
    item   = rep(c(&quot;item 1&quot;, &quot;item 2&quot;, &quot;item 3&quot;, &quot;item 4&quot;), each = 3)) %&gt;% 
    tidyr::expand(trial, group, result, item) %&gt;%
    mutate(count = round(runif(n = 48, min = 0, max = 10))) %&gt;%
    uncount(count)
  </code></pre>
  <p>I'm now trying to create a table that displays the row percentage for the results nested within each group (A or B). Those should be my the columns.
  The rows are the four items, nested within the different trials.
  I can manage to get row percentages within the groups, but my rows are unnecessarily doubled. How can I prevent that from happening?</p>
  <pre><code>test %&gt;%
    tab_cells(item) %&gt;%
    tab_cols(group %nest% result) %&gt;%
    tab_rows(trial) %&gt;%
    tab_subgroup(group ==&quot;A&quot;) %&gt;%
    #tab_stat_cases(label = &quot;N&quot;, total_label = &quot;&quot;) %&gt;%
    tab_stat_rpct(total_row_position = &quot;above&quot;, label=&quot;%&quot;, total_label = &quot;&quot;, total_statistic = c(&quot;u_rpct&quot;)) %&gt;% 
    tab_subgroup(group ==&quot;B&quot;) %&gt;%
    #tab_stat_cases(label = &quot;N&quot;, total_label = &quot;&quot;) %&gt;%
    tab_stat_rpct(total_row_position = &quot;above&quot;, label=&quot;%&quot;, total_label = &quot;&quot;, total_statistic = c(&quot;u_rpct&quot;)) %&gt;% 
    tab_pivot(stat_position = &quot;inside_rows&quot;)
  </code></pre>
  <p>The edit of <a href="https://stackoverflow.com/questions/58146656/expss-table-with-row-percentage-within-nested-variables-in-r">this solution</a> works partially for me but somehow creates for each column an additional empty column. So not sure what's going on. In addition, I would like to include two extra columns (before the answer columns) with the total count of observations per row/group.</p>
  <pre><code> |       |         |      |        |    |    A |              |      |    B |              |      |
   |       |         |      |        |    | Fail | Partial Pass | Pass | Fail | Partial Pass | Pass |
   | ----- | ------- | ---- | ------ | -- | ---- | ------------ | ---- | ---- | ------------ | ---- |
   | trial | Trial_A | item |      # |  % | 38.7 |         24.2 | 37.1 |      |              |      |
   |       |         |      |        |    |      |              |      | 24.6 |         29.2 | 46.2 |
   |       |         |      | item 1 |  % | 52.6 |         21.1 | 26.3 |      |              |      |
   |       |         |      |        |    |      |              |      | 40.0 |         30.0 | 30.0 |
   |       |         |      | item 2 |  % | 45.0 |         15.0 | 40.0 |      |              |      |
   |       |         |      |        |    |      |              |      |      |         28.6 | 71.4 |
   |       |         |      | item 3 |  % | 15.4 |         38.5 | 46.2 |      |              |      |
   |       |         |      |        |    |      |              |      | 33.3 |         16.7 | 50.0 |
   |       |         |      | item 4 |  % | 30.0 |         30.0 | 40.0 |      |              |      |
   |       |         |      |        |    |      |              |      | 15.4 |         46.2 | 38.5 |
   |       | Trial_B | item |      # |  % | 38.9 |         22.2 | 38.9 |      |              |      |
   |       |         |      |        |    |      |              |      | 29.2 |         38.5 | 32.3 |
   |       |         |      | item 1 |  % | 42.9 |          7.1 | 50.0 |      |              |      |
   |       |         |      |        |    |      |              |      | 30.4 |         34.8 | 34.8 |
   |       |         |      | item 2 |  % | 33.3 |         25.0 | 41.7 |      |              |      |
   |       |         |      |        |    |      |              |      |      |         50.0 | 50.0 |
   |       |         |      | item 3 |  % | 52.6 |         10.5 | 36.8 |      |              |      |
   |       |         |      |        |    |      |              |      | 53.8 |         38.5 |  7.7 |
   |       |         |      | item 4 |  % | 26.7 |         46.7 | 26.7 |      |              |      |
   |       |         |      |        |    |      |              |      | 21.7 |         39.1 | 39.1 |
  </code></pre>