title: Create a new column in R dataframe with row sum
body: <p>I am trying to do something in R that I thought was going to be pretty simple: add a new column with totals. </p>
  
  <p>I create a new dataset and I follow this <a href="https://stackoverflow.com/questions/4946873/how-do-i-add-a-row-to-a-data-frame-with-totals">suggestion</a>, but turns out that sum it calculates is wrong. I then followed another method that works, but I cannot attach the result as a column.</p>
  
  <pre class="lang-r prettyprint-override"><code>IUS_12_1_toy &lt;- c(2,4,4)
  IUS_12_2_toy &lt;- c(4,5,4)
  IUS_12_3_toy &lt;- c(3,4,4)
  IUS_12_4_toy &lt;- c(4,5,3)
  IUS_12_5_toy &lt;- c(4,4,4)
  IUS_12_6_toy &lt;- c(2,5,3)
  IUS_12_7_toy &lt;- c(4,5,4)
  IUS_12_8_toy &lt;- c(4,4,4)
  IUS_12_9_toy &lt;- c(3,4,4)
  IUS_12_10_toy &lt;- c(2,3,4)
  IUS_12_11_toy &lt;- c(3,4,2)
  IUS_12_12_toy &lt;- c(1,4,2)
  
  IUS_12_toy &lt;- data.frame(IUS_12_1_toy, IUS_12_2_toy, IUS_12_3_toy, 
                       IUS_12_4_toy, IUS_12_5_toy, IUS_12_6_toy,
                       IUS_12_7_toy,IUS_12_8_toy,IUS_12_9_toy,IUS_12_10_toy,
                       IUS_12_11_toy,IUS_12_12_toy)
  class(IUS_12_toy)
  #&gt; [1] "data.frame"
  class(IUS_12_1_toy)
  #&gt; [1] "numeric"
  library(janitor)
  #&gt; 
  #&gt; Attaching package: 'janitor'
  #&gt; The following objects are masked from 'package:stats':
  #&gt; 
  #&gt;     chisq.test, fisher.test
  IUS_12_toy %&gt;%
    adorn_totals("col")
  #&gt;  IUS_12_1_toy IUS_12_2_toy IUS_12_3_toy IUS_12_4_toy IUS_12_5_toy
  #&gt;             2            4            3            4            4
  #&gt;             4            5            4            5            4
  #&gt;             4            4            4            3            4
  #&gt;  IUS_12_6_toy IUS_12_7_toy IUS_12_8_toy IUS_12_9_toy IUS_12_10_toy
  #&gt;             2            4            4            3             2
  #&gt;             5            5            4            4             3
  #&gt;             3            4            4            4             4
  #&gt;  IUS_12_11_toy IUS_12_12_toy Total
  #&gt;              3             1    34
  #&gt;              4             4    47
  #&gt;              2             2    38
  
  # The problem is that the sum is wrong, as specified by:
  
  rowSums(IUS_12_toy)
  #&gt; [1] 36 51 42
  
  # OK, now I would like to add the results as a new column:
  
  IUS_12_toy[,13] = c("Total", rowSums(IUS_12_toy))
  
  # But I get an error:
  
  #&gt; Error in `[&lt;-.data.frame`(`*tmp*`, , 13, value = c("Total", "36", "51", : replacement has 4 rows, data has 3
  </code></pre>
  
  <p><sup>Created on 2019-09-28 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>