title: "Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one" message in R
body: <p>Say, I have the following data:</p>
  
  <pre><code>LungCap Age Height  Smoke   Gender  Caesarean
  6.475   6   62.1    no      male    no
  10.125  18  74.7    yes     female  no
  9.55    16  69.7    no      female  yes
  11.125  14  71      no      male    no
  4.8      5  56.9    no      male    no
  6.225   11  58.7    no      female  no
  </code></pre>
  
  <p>Now kindly look at the following command:</p>
  
  <pre><code>&gt; attach(LungCap6)
  &gt; tapply(Age, Smoke, mean, T)
  Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one
  &gt; length(Age)
  [1] 6
  &gt; tapply(X=Age, INDEX=Smoke, FUN=mean, na.rm=T)
    no  yes 
  10.4 18.0 
  &gt; tapply(Age, Smoke, mean, T)
  Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one
  &gt;
  </code></pre>
  
  <p>Why is the above error being given, and how to resolve it?</p>