Marginal means you can actually report
Today let's work out the one number a report actually wants for each cylinder group, and see why it is usually not that group's plain average.
Here is the mtcars dataset: 32 cars, each with a cylinder count, either 4, 6 or 8, and a transmission type, either automatic or manual, measured on fuel economy in mpg. A report on this data wants one number per cylinder count: its average mpg. That sounds like something tapply() already gives you. Before computing it, look at all 32 cars plotted together, colored by transmission.
Look at the colors within each cylinder count instead of just the overall spread. The 4-cylinder cars on the left are mostly the manual color. The 8-cylinder cars on the right are mostly the automatic color. Each cylinder group is not just a pile of mpg values, it is a pile with its own particular mix of transmission types sitting inside it, and that mix is different from one group to the next.
Why a raw group mean is confounded by an uneven mix
Let's compute the obvious average anyway, and see exactly where that mix causes trouble.
4-cylinder cars average 26.66 mpg, 6-cylinder cars average 19.74, and 8-cylinder cars average 15.10. On its own that looks like a complete answer: three cylinder counts, three averages, done.
Now look at the second table. Transmission is coded 0 for automatic and 1 for manual, and it is nowhere near evenly spread across the three cylinder counts. The 4-cylinder group holds 3 automatic cars and 8 manual ones. The 8-cylinder group is close to the mirror image: 12 automatic cars and only 2 manual. The 6-cylinder group sits roughly in between, at 4 and 3.
That split matters because transmission type, on its own, moves mpg by a lot.
Automatic cars average 17.15 mpg. Manual cars average 24.39, about 7 mpg higher, regardless of cylinder count. So the 4-cylinder group's raw mean of 26.66 is not purely measuring what 4 cylinders does to mpg. It is also picking up the fact that 8 of its 11 cars happen to be the higher-mileage manual kind. The 8-cylinder group has the opposite problem: its raw mean of 15.10 is weighed down by having almost no manual cars to lift it. Neither number is a clean read on cylinder count alone. Each one is a blend of cylinder count and whatever transmission mix happened to land in that group, and the two groups' mixes are not even close to the same. This is what confounded means here: cylinder count and transmission type are tangled together in the raw average, and that single number gives you no way to tell how much of it is one and how much is the other.