I have a set of car sales data and I subset my data into different groups as the following:
Car brand and sales year.
toyota=subset(car, brand=="Toyota")
toyota.yr = cut(toyota$date, "year")
honda=subset(car, brand=="Honda")
honda.yr = cut(honda$date, "year")
etc.
so now I have 6 subgroup for the car brands and then I use tapply to get the mean of sales of each brand by year:
tapply(toyota$price, toyota.yr, mean, na.rm=TRUE)
I would like to do this to all 6 subgroups, is there anyway I can do this at one time rather than typing the tapply function for 6 times?
I appreciate any helps, thanks!