[R] Ignorant lack of bliss : summarise table by column attribute

Jason Turner jasont at indigoindustrial.co.nz
Tue Apr 6 22:19:22 CEST 2004


Using the data you supplied, and the work you've done so far, I also did 
this:

## make sure R knows that "group" isn't numeric
## might not be necessary, depending how you imported your data.
results$group <- factor(results$group)

Since you attached the data frame, then altered it, a warning is in 
order:  as the help page for "attach" says, the altered copy and the 
attached copy are *two different objects*.  Beware.  See the help page 
for "with" for a less confusing way to save typing.

results$resid <- results$projected - results$finalreading


Rory Campbell-Lange wrote:
 > Aims:
 >
 >     - Summarise these by groups (I can't work out how to use tapply...)


## some fun stats
tapply(results$resid, results$group, fivenum)
tapply(results$resid, results$group, mean)
tapply(results$resid, results$group, sd)
...

## nice plots:
library(lattice)
dotplot(group ~ resid, data=results)
bwplot(group ~ resid, data=results)

>     - Produce a sensible 'typification' of each group's change in
>       relation to the projected figure. I assume this would use a
>       statistical algorithm to exclude exceptions.

You'll want input from a Real Statistician for that.  This will get you 
both started:

res.mod <- lm(resid ~ group, data=results)
summary(res.mod)
plot(res.mod)

## before proceeding, find someone who understands the
## following help page.
help(p.adjust)

> If I needed to learn more is the book "Introductory Statistics with R" a
> good place to start?

Definately.  Among other things, it'll explain the cryptic remark above 
about the help page.

After you've munched through that book, get "Modern Applied Statistics 
with S", by Venables and Ripley, published by Springer-Verlag, 
preferably the 4th edition (2002).

They're both great texts for their jobs.

Cheers

Jason




More information about the R-help mailing list