title: How to sum cells with a splitting criterion?
body: <p>I have three different treatments and within each one I have five sample values. I am into difficulties in how to sum the five values corresponding at each treatment.</p>
  
  <p>Really I am working with a big dataframe which management is not too easy for me.</p>
  
  <p>Below there is the dataframe <code>dataexample_2</code> and the srcipt that I am using but with non positive results (see below):</p>
  
  <pre><code>Treatment   Variable
  A1  0.020408163
  A1  0.040816327
  A1  0.06122449
  A1  0.081632653
  A1  0.102040816
  A2  0.12244898
  A2  0.142857143
  A2  0.163265306
  A2  0.183673469
  A2  0.204081633
  A3  0.224489796
  A3  0.244897959
  A3  0.265306122
  A3  0.285714286
  A3  0.306122449
  
  names(dataexample_2)
  summary(dataexample_2)
  
  
  Add&lt;-sapply(split(dataexample_2, dataexample_2$Treatment), function(d)     sum(dataexample_2$Variable,na.rm = FALSE))
  Table&lt;-as.data.frame(Add)
  </code></pre>
  
  <p>I am obtaining:</p>
  
  <pre><code>     Add
  A1 2.44898
  A2 2.44898
  A3 2.44898
  </code></pre>
  
  <p>And I wish to obtain:</p>
  
  <pre><code>     Add
  A1 0.3061
  A2 0.8163
  A3 1.3265
  </code></pre>
  
  <p>Any help will be really appreciated. Thanks in advance. Regards. Matías.</p>