title: R: Non-numeric argument to mathematical function
body: <p>I have written a userdefined function:</p>
  
  <pre><code>epf &lt;- function(z,x,noise=std_noise){
      z_dims &lt;- length(z)
      std_noise &lt;- 0.5*matrix(1,1,z_dims)
      std_noise &lt;- as.data.frame(std_noise)
  
      obs_prob &lt;- dnorm(z,x[1:z_dims],noise)
  
      error &lt;- prod(cbind(1,obs_prob))
      return(error)
  }
  </code></pre>
  
  <p>This function is called in a for-loop in another function:</p>
  
  <pre><code>w &lt;- matrix(0,N,1)
          for (i in 1:N){
              w[i] &lt;- epf(z,p[i,],R_noise) 
          }
  </code></pre>
  
  <p>where <code>z</code> is a 2-dimensional vector, <code>N=1000</code>,  <code>p</code> is a dataframe of 1000 observations and 4 variables and <code>R_noise</code> is a dataframe og 1 observation and 4 variables.</p>
  
  <p>Here I get the error: "Non-numeric argument to mathematical function", for the line <code>obs_prob &lt;- dnorm(z,x[1:z_dims],noise)</code></p>
  
  <p>Can anyone help me with finding the error?</p>
  
  <p>I have looked through questions similar to mine, but I still can't find the error in my code.</p>
  
  <p>Edit:<br>
  Added definition of <code>N</code></p>