title: How to compute the sum of a vector in r using a for loop
body: <p>I would like to ask how I can compute the sum of a vector in R without using one of the the ready functions (sum, mean etc). Sorry for the silly question!!!</p>
  
  <p>I tried the following but it did not work. Could you tell me what I am doing wrong?
  The code is:</p>
  
  <pre><code>x&lt;-c(1,2,3)
  sumfun&lt;-function(y){
  sum&lt;-0
  for(i in 1:(length(y)-1)){
  sum=sum+y[i]
  }
  print(sum)
  }
  sumfun(x)
  </code></pre>