Call:
lm(formula = m[, 2] ~ m[, 3])
Coefficients:
(Intercept) m[, 3]
0.04288 1.17918
------------------------------------------------------------
aba$Gender: I
Call:
lm(formula = m[, 2] ~ m[, 3])
Coefficients:
(Intercept) m[, 3]
0.02997 1.21833
------------------------------------------------------------
aba$Gender: M
Call:
lm(formula = m[, 2] ~ m[, 3])
Coefficients:
(Intercept) m[, 3]
0.03653 1.19480
Calls toby()look very similar to calls totapply(), with the first argument
specifying our data, the second the grouping factor, and the third the func-
tion to be applied to each group.
Just astapply()forms groups of indices of a vector according to levels
of a factor, thisby()call finds groups of row numbers of the data frameaba.
That creates three subdata frames: one for each gender level of M, F, and I.
The anonymous function we defined regresses the second column of
its matrix argumentmagainst the third column. This function will be called
three times—once for each of the three subdata frames created earlier—
thus producing the three regression analyses.
6.3 Working with Tables........................................................
To begin exploring R tables, consider this example:
> u <- c(22,8,33,6,8,29,-2)
> fl <- list(c(5,12,13,12,13,5,13),c("a","bc","a","a","bc","a","a"))
> tapply(u,fl,length)
abc
52NA
Factors and Tables 127