title: Indexing variables in R
body: <p>I am normally a maple user currently working with R, and I have a problem with correctly indexing variables. </p>
  
  <p>Say I want to define 2 vectors, v1 and v2, and I want to call the nth element in v1. In maple this is easily done: 
  v[1]:=some vector, </p>
  
  <p>and the nth element is then called by the command 
  v[1][n]. 
  How can this be done in R? The actual problem is as follows:</p>
  
  <p>I have a sequence M (say of length 10, indexed by k) of simulated negbin variables. For each of these simulated variables I want to construct a vector X of length M[k] with entries given by some formula. So I should end up with 10 different vectors, each of different length. My incorrect code looks like this</p>
  
  <pre><code>sims&lt;-10
  M&lt;-rnegbin(sims, eks_2016_kasko*exp(-2.17173), 840.1746)
  for(k in 1:sims){
                   x[k]&lt;-rep(NA,M[k])
                   X[k]&lt;-rep(NA,M[k])
  for(i in 1:M[k]){x[k][i]&lt;-runif(1,min=0,max=1)
                    if(x[k][i]&gt;=0 &amp; x[i]&lt;=0.1056379){
                      X[k][i]&lt;-rlnorm(1, 6.228244, 0.3565041)}
    else{
      X[k][i]&lt;-rlnorm(1, 8.910837, 1.1890874)
    }
   }
  }
  </code></pre>
  
  <p>The error appears to be that x[k] is not a valid name for a variable. Any way to make this work?</p>
  
  <p>Thanks a lot :)</p>