Loop to generate string and variables : <p>I have a set of confusionMatrixes of 100 models like wynik1, ... wynik100.</p>

<p>I want to have a vector of accuracies of all of these models.</p>

<p>I have written a loop, but it does not work.</p>

<p>Where is the problem?</p>

<p>The task is to generate strings and variables from the strings:</p>

<pre><code>confusionMatrix(m2pred,cats$Sex)-&gt; wynik1
...

accuracy &lt;- NULL
b_accuracy &lt;- NULL
for (i in 1:100){
  name &lt;- paste0("wynik",i)
  ac&lt;- name$overall[1]
  bac&lt;- name$byClass[11]
  accuracy &lt;- c(accuracy, ac)
  b_accuracy &lt;- c(b_accuracy, bac)
}
accuracy
</code></pre>

<p>The output is:</p>

<blockquote>
<pre><code>Error in nazwa$overall : $ operator is invalid for atomic vectors
&gt; accuracy
NULL
</code></pre>
</blockquote>
