title: KnapSack dynamic programming in R with recursive function
body: <p>I created this simple code in R to solve the Knapsack program with a recursive funtion</p>
  
  <pre><code>n &lt;- c(0,1,2,3,4)
  v &lt;- c(10,40,30,50)
  w &lt;- c(5,4,6,3)
  k &lt;- 10
  
  
  myfunction  &lt;- function(n,k){
    if (n==0 | k==0){
    output &lt;- 0
    } else if (w[i] &gt; k) {
          output &lt;- myfunction[i-1,w]
    } else {
          output &lt;- max(v[i]+ myfunction(i-1, k-w[i]),myfunction(i-1,k))
        }
  return(myfunction)
  }
  </code></pre>
  
  <p>However, I don't get a value as an output, but the whole function. For example if I put in: 
      myfunction(4,10)</p>
  
  <p>I don't get an value of 90, but the whole funtion typed out.</p>
  
  <p><a href="https://i.stack.imgur.com/h4NnJ.png" rel="nofollow"><img src="https://i.stack.imgur.com/h4NnJ.png" alt="enter image description here"></a></p>
  
  <p>these are the values</p>