title: Dynamic Variables in R
body: <p>I am using RStudio (ver. 3.0.2) and new to R. </p>
  
  <p>In my task, would like to create the below variables in RScript and assign a value.</p>
  
  <pre><code>AA_1_11 &lt;- 1
  AA_2_22 &lt;- 2
  AA_3_33 &lt;- 3
  AA_4_44 &lt;- 4
  BB_1_11 &lt;- 5
  BB_2_22 &lt;- 6
  BB_3_33 &lt;- 7
  BB_4_44 &lt;- 8
  </code></pre>
  
  <p>Rather to statically create the 8 lines above. I am intending to dynamically code those so that the codes are useful when the variables expand in future i.e AA,BB, could later extend to CC, DD etc.</p>
  
  <p>Tried the below code:</p>
  
  <pre><code>char_list &lt;- c("AA", "BB")
  num_list &lt;- c("1_11", "2_22", "3_33", "4_44")
  
  i=1
  char_num_array &lt;-vector()
  for (char in char_list) {
    for (num in num_list) {
      char_num_array[i] &lt;- paste(char,num, sep = '_') 
      i &lt;- i + 1
    }
  }
  
  (char_num_array)
  
  for (j in 1:length(char_num_array)){ 
     char_num_array[j] &lt;- j
  }
  </code></pre>
  
  <p>Though I can create all the variables names as a string name, have no idea why the actual variables are not created in RStudio as shown in the picture below.</p>
  
  <p><img src="https://i.stack.imgur.com/4K06N.png" alt="enter image description here"></p>
  
  <p>Hope you can guide me on this.</p>
  
  <p>Update:</p>
  
  <p>Thanks to all for your help. I really wanted to make separate variables so I can monitor the changes in the values on RStudio as the variables will continually be used for other manipulations i.e fitting, refitting etc. </p>
  
  <p>Thanks to JDB. I have modified the codes to below, where <em>i</em> could be replaced with other mathematical equation.</p>
  
  <pre><code>char_list &lt;- c("AA", "BB")
  num_list &lt;- c("1_11", "2_22", "3_33", "4_44")
  
  i &lt;- 1
  for (char in char_list) {
    for (num in num_list) {   
      assign(paste(char,num, sep = '_'), i)       
      i &lt;- i + 1
    }
  }
  </code></pre>