For loop outputting the wrong answer
<p>The code below is an example. My function <code>testf</code> works fine when calling <code>NAME</code> or <code>SRC</code> individually but it doesn't work if I try to do this through a vector - make sense I believe. So I ventured into making it a loop and by rights (from what I do understand) this should work, but it hasn't. It generates an output but it's clearly wrong and I'm not sure why it's doing this. Am I applying this incorrectly? Thanks</p>

<pre><code>NAME &lt;- c("SYNOP", "SYNOP", "METAR", "METAR", "SYNOP", "METAR")
AIR &lt;-  c(6.7, 8.3, 9.2, 8.9, 9.1, 8.7)
SRC &lt;- c("WMO", "WMO", "WMO", "ID_3", "ID_3", "WMO")
Example &lt;- data.frame(NAME, AIR, SRC)

require(dplyr)
testf &lt;- function(j) {
Example %&gt;% group_by((j)) %&gt;% summarize(Count=n())
}

testf(NAME)
testf(SRC)

vector &lt;- c("NAME", "SRC")

testf(vector)

for (v in vector) {
testg &lt;- testf(v)
print(testg)
  }
</code></pre>