problem-4.16
problem-4.16
This can be done as follows:
> before.72 = year < 72 & year > 0
> tapply(runs.scored[before.72],league[before.72],mean)
AL NL
653.9 673.9
> tapply(runs.scored[!before.72],league[!before.72],mean)
AL NL
718.7 675.6
Alternatively, tapply() can use two factors to split up the
results in one command.
> tapply(runs.scored,list(factor(before.72),league),mean)
AL NL
FALSE 718.7 675.6
TRUE 653.9 673.9
The tapply() syntax above uses a list of factors to split up
the value of runs.scored.