Extracting a series of integers using a loop
<p>I have some data where I want to extract the frequency with which the integers appear. Here is some sample data:</p>

<pre><code>df &lt;- read.table(header=T, text="A B C D 
1          1         5          3         1  
2          1         2          3         2  
3          2         3          5         3  
4          1         4          5         3  
5          3         1          4         2  
6          5         2          5         1 
") 
df
</code></pre>

<p>I can loop through these and get the counts as follows: </p>

<pre><code>for (i in 1:5){ 
 print(colSums(df==i))
}
</code></pre>

<p>But every time I try to store the output I get an error. What is the neatest way to store the resultant output in a dataframe? I think I'm getting confused about the way to store data that's run through a loop. Thanks for your help. </p>