title: R error in unique.default(x) unique() applies only to vectors
body: <p>I created a dataset  named <code>state</code>  from the built-in matrix <code>state.x77</code> with two continuous variables (Population and Income) and two factor variables (region and area).</p>
  
  <p>I computed mean income by region using <code>tapply()</code>, <code>by()</code>, <code>aggregate()</code>, and <code>ave()</code> to see the format of the returned object.</p>
  
  <p>But the call to <code>ave()</code> is giving the error </p>
  
  <blockquote>
    <p>Error in unique.default(x) : unique() applies only to vectors</p>
  </blockquote>
  
  <p>The code is: </p>
  
  <pre><code>## Mean income by region
  tapply(state$inc, state$region, mean)
  # Northeast         South North Central          West 
  # 4570.222       4011.938      4611.083      4702.615 
  
  by(state$inc, state$region, mean)
  # state$region: Northeast
  #
  # [1] 4570.222
  # [...]
  
  aggregate(state$inc, list(state$region), mean)
  #
  #         Group.1        x
  # 1     Northeast 4570.222
  # 2         South 4011.938
  # 3 North Central 4611.083
  # 4          West 4702.615
  
  ave(state$inc, state$region, mean)
  # Error in unique.default(x) : unique() applies only to vectors
  </code></pre>
  
  <p>Why is the error occurring? How can I prevent it?</p>