title: colMeans function in R and running into problems with columns of size 1
body: <p>I had a question regarding the colMeans function.  Is there a version of this that will not return an error when it runs into a column of length one?  For example</p>
  
  <pre><code>temp&lt;-cbind(c(2,2),c(3,4))
  colMeans(temp)
  
  [1] 2.0 3.5
  </code></pre>
  
  <p>But for this one</p>
  
  <pre><code>temp2&lt;-c(2,2)
  colMeans(temp2)
  
  Error in colMeans(temp2) : 
  'x' must be an array of at least two dimensions
  </code></pre>
  
  <p>But, if I apply the function mean to each column it properly comes up with the value of 2 and 2.  </p>
  
  <p>I wrote a function to do this</p>
  
  <pre><code>testfun&lt;-function(i,x){
  mean(x[,i])
  }
  sapply(1:ncol(x),testfun,x)
  </code></pre>
  
  <p>which gives the same results as colMeans.<br>
  I've heard that colMeans is supposed to be much faster than this method.  So, is there a version of colMeans that will work when my column is of size 1.  </p>