aggregate.data.frame(x, by, FUN, ...)
aggregate(state.x77, list(Region=state.region), mean)# Gives the following output: Region Population Income Illiteracy Life.Exp Murder HS.Grad 1 Northeast 5495.111 4570.222 1.000000 71.26444 4.722222 53.96667 2 South 4208.125 4011.938 1.737500 69.70625 10.581250 44.34375 3 North Central 4803.000 4611.083 0.700000 71.76667 5.275000 54.51667 4 West 2915.308 4702.615 1.023077 71.23462 7.215385 62.00000 Frost Area 1 132.7778 18141.00 2 64.6250 54605.12 3 138.8333 62652.00 4 102.1538 134463.00
aggregate(state.x77, list(Region=state.region, Cold=state.x77[,"Frost"]>130), mean)
# Gives the following output: Region Cold Population Income Illiteracy Life.Exp Murder 1 Northeast FALSE 8802.8000 4780.400 1.1800000 71.12800 5.580000 2 South FALSE 4208.1250 4011.938 1.7375000 69.70625 10.581250 3 North Central FALSE 7233.8333 4633.333 0.7833333 70.95667 8.283333 4 West FALSE 4582.5714 4550.143 1.2571429 71.70000 6.828571 5 Northeast TRUE 1360.5000 4307.500 0.7750000 71.43500 3.650000 6 North Central TRUE 2372.1667 4588.833 0.6166667 72.57667 2.266667 7 West TRUE 970.1667 4880.500 0.7500000 70.69167 7.666667 HS.Grad Frost Area 1 52.06000 110.6000 21838.60 2 44.34375 64.6250 54605.12 3 53.36667 120.0000 56736.50 4 60.11429 51.0000 91863.71 5 56.35000 160.5000 13519.00 6 55.66667 157.6667 68567.50 7 64.20000 161.8333 184162.17