R error in unique.default(x) unique() applies only to vectors

This is a very common mistake, you need to use the named argument FUN:

ave(state$inc, state$region, FUN = mean)

otherwise mean will be interpreted as another grouping variable (part of the ... argument to ave.)

Leave a Comment