[R] t test on data frame

Bart Joosen bartjoosen at hotmail.com
Fri Nov 4 10:09:41 CET 2005


I have constructed a dataframe as follows:

Oil <- rep(c("Oil1","Oil2","Oil3"),8)
Comp <- rep(rep(c("C1","C2"),c(4,4)),3)
Mth <- rep(c("M1","M1","M2","M2"),6)
Meas <- rep(c(1,2),12)
Result <- rnorm(24,mean=100, sd=5)
df <- data.frame(Oil, Comp, Mth, Meas, Result)

The same compound (Comp) is found in different oils.
Now I want to see if there are differences in method per compound.
I tried this one:
df.t <- t.test(Result~Mth | Comp, df)

But I get:
Error in t.test.formula(Result ~ Mth | Comp, df) :
         grouping factor must have exactly 2 levels
In addition: Warning message:
| not meaningful for factors in: Ops.factor(Mth, Comp)

How can I get my results like:
Comp1: Mean Mth 1: ....
           Mean Mth 2: ...
           t = ....
Comp 2: ....

Is this possible?
And please: How can I do it?

Kind regards


More information about the R-help mailing list