Q:

"Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one" message in R

Say, I have the following data:
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

Now kindly look at the following command:
> attach(LungCap6)
> tapply(Age, Smoke, mean, T)
Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one
> length(Age)
[1] 6
> tapply(X=Age, INDEX=Smoke, FUN=mean, na.rm=T)
  no  yes 
10.4 18.0 
> tapply(Age, Smoke, mean, T)
Error in mean.default(X[[i]], ...) : 'trim' must be numeric of length one
>

Why is the above error being given, and how to resolve it?

A:

trim= is the second argument of the function mean(), and you don't want to pass TRUE to that argument when called within tapply(). That's what tapply() does, it passes extra args preserving the order to the function it calls.
Thus, you have to explicitly name the argument you want to send TRUE, in this case na.rm=, since it is the 3rd and not the 2nd argument to mean():
> attach(LungCap6)
> tapply(Age, Smoke, mean, na.rm=TRUE)

Check the argument order with ?mean

