0

How to sum multiple column using aggregate function (formula method) ? I am trying to work following code;

aggregate(cty,hwy ~ class+ Manufacturer, data = mpg, mean)

it should give me sum of hwy, sum of cty by manufacturer and class

Fahadakbar
  • 458
  • 6
  • 23
  • This should get you there using dplyr, not agg: `df% dplyr::group_by(class+ Manufacturer) %>% dplyr::summarise(total=sum(cty), total2 = sum(hwy))` – Duke Showbiz Oct 12 '18 at 14:46
  • ahh... that was simple, i tried c(cty,hwy) but that didn't work so i thought i might have been something else . Thank you so much – Fahadakbar Oct 12 '18 at 14:47

0 Answers0