title: dim() Error in outer
body: <p>I have made the following function I would like to make a 3-dimensional image of using the function "persp", therefore I use the function outer, to get the value of the function for each combination of a and b, but this make an Error. </p>
  
  <p>So my code is:</p>
  
  <pre><code>a&lt;- seq(from=0, to=5,by=0.25)
  b&lt;- seq(from=0.1, to=2,by=0.1)
  
  Rab &lt;- function(a,b){
    r &lt;- matrix(ncol = 1, nrow = 4)
    for (p in seq(from=0, to=4,by=1)){
    g &lt;- ifelse(a&gt;=0 &amp; a&lt;1-1/p &amp; p &gt;b, a*p,
           ifelse(a&gt;=0 &amp; a&lt;1-1/b &amp; p&lt; b, -1+(a+1/b),
                  ifelse(a &gt; 1-1/max(p,b),-1+p,NA)))
    w &lt;- p
    r[w] &lt;- g
    }
    return(r)
  } 
  
  q &lt;- outer(a,b,Rab)
  </code></pre>
  
  <p>And then I get the following Error and warning messages, which I don't understand.  </p>
  
  <pre><code>Error in outer(a, b, Rab) : 
    dims [product 420] do not match the length of object [4]
  In addition: Warning messages:
  1: In r[w] &lt;- g :
    number of items to replace is not a multiple of replacement length
  2: In r[w] &lt;- g :
    number of items to replace is not a multiple of replacement length
  3: In r[w] &lt;- g :
    number of items to replace is not a multiple of replacement length
  4: In r[w] &lt;- g :
    number of items to replace is not a multiple of replacement length
  </code></pre>
  
  <p>I have tried to read about it, and I think it is because I have constructed the function Rab wrong, but I don't know how to correct it.</p>
  
  <p>Any help is appreciated. </p>