Invalid length error for beginner
<p>I have checked previous questions but couldn't find an answer</p>

<pre><code> columnmean&lt;-function(y){
    n&lt;-ncol(y)
    means&lt;-numeric(n)
    for(i in 1:n){
        means[i]&lt;-mean(y[,i])
    }
    means}
</code></pre>

<p>I simply cannot understand the error, even the code seems right. Also, i get some dimension error if i input the value of n in this line    </p>

<pre><code> means[i]&lt;-mean(y[,i])
</code></pre>