usage of tapply with FUN = function(x){}
<p>In my task I want to find the mean of temperature by the gender. We can do this by tapply command. Also I am not allowed to use mean command:</p>

<pre><code>tapply(df$temperature,df$gender,FUN = function(x){sum(x)/length(df[,1])})
</code></pre>

<p>but it gives me wrong result. It just devide the result by 2, instead of finding mean of both gender.
How can I fix that?
Because with aggregate function everything works correct:</p>

<pre><code>  aggregate(df$temperature,by = list(df$gender),function(x){sum (x)/length(x)})
</code></pre>