title: Area under the curve
body: <p>I have my data in long-format like this with 20 different variables (but they all have the same Time points):</p>
  
  <pre><code>   Time variable value
  1    0       P1  0.07
  2    1       P1  0.02
  3    2       P1  0.12
  4    3       P1  0.17
  5    4       P1  0.10
  6    5       P1  0.17
  
  
  66     0      P12  0.02
  67     1      P12  0.11
  68     2      P12  0.20
  69     3      P12  0.19
  70     4      P12  0.07
  71     5      P12  0.20
  72     6      P12  0.19
  73     7      P12  0.19
  74     8      P12  0.12
  75    10      P12  0.13
  76    12      P12  0.08
  77    14      P12    NA
  78    24      P12  0.07
  79     0      P13  0.14
  80     1      P13  0.17
  81     2      P13  0.24
  82     3      P13  0.24
  83     4      P13  0.26
  84     5      P13  0.25
  85     6      P13  0.21
  86     7      P13  0.21
  87     8      P13    NA
  88    10      P13  0.19
  89    12      P13  0.14
  90    14      P13    NA
  91    24      P13  0.12
  </code></pre>
  
  <p>I would like to calculate the area under the curve for each variable between <code>time=0</code> and <code>time=24</code>. Ideally I would also like to calculate area under the curve where <code>y&gt;0.1</code>.</p>
  
  <p>I have tried the pracma package but it just comes out with NA.</p>
  
  <pre><code>trapz(x=P2ROKIlong$Time, y=P2ROKIlong$value)
  </code></pre>
  
  <p>Do I have to split my data into lots of different vectors and then do it manually or is there a way of getting it out of the long-format data?</p>