title: R Surface Plot from List of X,Y,Z points
body: <p>I am trying to make a surface plot for data that is in a very long list of x,y,z points.  To do this, I am dividing the data into a grid of 10k squares and finding the max value of z within each square.  From my understanding, each z value should be stored in a matrix where each element of the matrix corresponds to a square on the grid.  Is there an easier way to do this than the code below?  That last line is already pretty long and it is only one square.</p>
  
  <pre><code>x&lt;-(sequence(101)-1)*max(eff$CFaR)/100
  y&lt;-(sequence(101)-1)*max(eff$EaR)/100
  effmap&lt;-matrix(ncol=length(x)-1, nrow=length(y)-1)
  someMatrix &lt;- max(eff$Cost[which(eff$EaR[which(eff$CFaR &gt;= x[50] &amp; eff$CFaR &lt;x[51], arr.ind=TRUE)]&gt;=y[20] &amp; eff$EaR[which(eff$CFaR &gt;= x[50] &amp; eff$CFaR &lt;x[51], arr.ind=TRUE)]&lt; y[91])])
  </code></pre>