How to average all columns in dataset by group : <p>I'm using aggregate in R to try and summarize my dataset. I currently have 3-5 observation per ID and I need to average these so that I have 1 value (the mean) per ID. Some columns are returning all "NA" when I use aggregate. </p>

<p>So far, I've created a vector for each column to average it, then tried to use merge to combine all of them. Some columns are characters, so I tried converting them to numbers using as.numeric(as.character(column)), but that returns too many NA in the column. </p>

<pre><code>library(dplyr)
Tr1 &lt;-  data %&gt;% group_by(ID) %&gt;% summarise(mean = mean(Tr1))
Tr2 &lt;-  data %&gt;% group_by(ID) %&gt;% summarise(mean = mean(Tr2))
Tr3 &lt;-  data %&gt;% group_by(ID) %&gt;% summarise(mean = mean(Tr3))
data2 &lt;- merge(Tr1,Tr2,Tr3, by = ID)
</code></pre>

<p>From this code I get error codes: </p>

<pre><code>There were 50 or more warnings (use warnings() to see the first 50)
</code></pre>

<p>then,</p>

<pre><code>Error in fix.by(by.x, x) : 
'by' must specify one or more columns as numbers, names or logical
</code></pre>

<p>My original dataset looks like:</p>

<pre><code>ID Tr1 Tr2 Tr3
1 4 5 6
1 5 3 9
1 3 5 9
4 5 1 8
4 2 6 4 
6 2 8 6
6 2 7 4
6 7 1 9 
</code></pre>

<p>and I am trying to find a code so that it looks like:</p>

<pre><code>ID Tr1 Tr2 Tr3
1 4   4.3 8
4 3.5 3.5 6 
6 3.7 5.3 6.3
</code></pre>
