I'm having a bit of trouble with a function i am writing.
I have one set of values I want to put in the first column of my prescribed b x 2 matrix and another set of values I want to put in the second column. 
Here is my code so that it makes more sense
sampl=function(v,b) {
  output=matrix(0,ncol=2,nrow=b)
  sumj=0
  av=0
  n=length(v)
  for (i in 1:b) {
    for (j in 1:n) {
      k=sample(v,n,replace=T)
      av[i]=mean(k)
      sumj[i]=sum((k[j]-mean(k))^2)
      output[i,1]=sumj[i]
      output[i,2]=av[i]
    }
  }
  output
}
but this is coming up with
Error in `[<-`(`*tmp*`, i, 2, value = -1.88) : subscript out of bounds
output[i,1] seems to work but output[i,2] seems to raise the error up. 
your help would be appreciated 
 
    