title: How to calculate volume under 3D-surface in R
body: <p>I'd like to calculate the volume under my surface in R, but don't know how...
  My example data:</p>
  <pre><code>set.seed(94756)
  mat &lt;- matrix(sample(1:1000,500,replace = TRUE),ncol = 20)  
  mat &lt;- as.data.frame(mat)
  
  library(dplyr)
  fig1 &lt;- add_column(mat, id = seq(0.2, nrow(mat)*0.2,0.2), .before = &quot;V1&quot;)
  fig2 &lt;- rbind(seq(0, ncol(fig1)*2,2), fig1) 
  
  
  colnames(fig2) &lt;- fig2[1,]
  fig2 &lt;- fig2[2:nrow(fig2),]
  
  row.names(fig2) &lt;- fig2$`0`
  fig2[1] &lt;- NULL
  
  
  library(plotly)
  mat &lt;- as.matrix(mat)
  df &lt;- plot_ly(z = ~mat)
  df &lt;- df %&gt;% add_surface()
  df
  
  </code></pre>
  <p>I think I have to create a block with min, max and calculate with integrals. But not sure how exactly...
  If anyone can, it would be great! Thanks in advance!</p>