How to compute integral of an array
<p>I am wondering if there is a way to perform integral on arrays in R.
I have arrays <code>S</code> and <code>R</code>. I want to integrate them over pressure level (<code>P</code>) from 1000 to 850. How can I do this?</p>

<p><a href="https://i.stack.imgur.com/x3zPR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x3zPR.jpg" alt="enter image description here"></a>.</p>

<p>The <code>S</code>, <code>R</code> and <code>P</code> data are</p>

<pre><code>S&lt;-structure(c(0.0011979939772106, 0.0011979939772106, 0.0011979939772106, 
0.00122851820731487, 0.00122654890214685, 0.00122457959697883, 
0.00124164690843498, 0.00123705186304294, 0.0012324568176509, 
0.00133617355649982, 0.00133617355649982, 0.00133617355649982, 
0.00138048292278021, 0.00137752896502818, 0.00137457500727616, 
0.00140575567243643, 0.00139951953940438, 0.00139328340637232, 
0.00139820666929237, 0.00139820666929237, 0.00139820666929237, 
0.00151308280409338, 0.00150192340814128, 0.00149076401218919, 
0.00155575108273376, 0.00154426346925366, 0.00153277585577356
), .Dim = c(3L, 3L, 3L))
</code></pre>



<pre><code>R&lt;-structure(c(-15.1752538162522, -15.1929331135921, -15.2092524649828, 
-16.2142525214608, -16.2400914944961, -16.2604906837345, -17.2355719293295, 
-17.2641307942633, -17.2858899294509, -13.3842050011216, -13.4059641363092, 
-13.4250033795984, -14.3266475439352, -14.3361671655798, -14.3402470034274, 
-15.3466070058547, -15.3398072761085, -15.3262078166163, -10.7132711568418, 
-10.7350302920294, -10.7554294812678, -11.8379464568517, -11.8066677000195, 
-11.7726690512888, -13.8003484615847, -13.7187517046312, -13.6317151638807
), .Dim = c(3L, 3L, 3L))
</code></pre>



<pre><code>P&lt;-c(1000,950,900,850)
</code></pre>

<p>I tried the following and could not figure out how I can perform integral for an array.</p>

<pre><code>f &lt;- function(x) {x}
inr &lt;- integrate(f,1000,850) #where f would be a function.
</code></pre>