title: Trying to initialize a multidimensional vector in R
body: <p>I am using knn to make estimates of random data, and I am choosing different k's from a vector. Each knn returns a vector of length 200, and I have 13 k's, so I need a 13x200 vector initialized before the for loop. I want to do something like</p>
  
  <pre><code>knn_train &lt;- rep(0,1000)
  </code></pre>
  
  <p>But for a multidimensional vector. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>library(class)
  library(MASS)
  #List of k's for use in knn
  k &lt;- c(1,4,7,10,13,16,30,45,60,80,100,150,200)
  #Generate identity matrix for sigmas 
  sigma &lt;- diag(2)
  # Class 1
  mu_green &lt;- c(-.5,.5)
  green_train &lt;- mvrnorm(100, mu_green,sigma)
  green_test &lt;-  mvrnorm(100, mu_green,sigma)
  #Class 0
  mu_red &lt;-c(-.2,.6)
  red_train&lt;- mvrnorm(100, mu_red,sigma)
  red_test&lt;- mvrnorm(100, mu_red,sigma)
  #Bind test and train data
  train &lt;- rbind(green_train,red_train)
  test &lt;- rbind(green_test,red_test)
  cl &lt;- rbind(c(rep(1,100),rep(0,100)))
  
  
  for(i in 1:length(k))
  {
    #Train into train then train into test
    knn_train[i] = knn(train,train,cl,k[i],prob=TRUE)
    knn_test[i] = knn(train,test,cl,k[i],prob=TRUE)
    #First 100 are class 1, second 100 are class 2
    train_err[i]&lt;- 100-sum(table(knn_train[i][1:100]))+sum(table(knn[i][100:200]))
    test_err[i]&lt;- 100-sum(table(knn_test[i][1:100]))+sum(table(knn[i][100:200]))
  }
  </code></pre>