I created a dataset named state from the built-in matrix state.x77 with two continuous variables (Population and Income) and two factor variables
state
state.x77
This is a very common mistake, you need to use the named argument FUN:
FUN
ave(state$inc, state$region, FUN = mean)
otherwise mean will be interpreted as another grouping variable (part of the ... argument to ave.)
mean
...
ave