[R] suggestion for paired t-tests

Juliet Hannah juliet.hannah at gmail.com
Sat Jul 25 17:01:08 CEST 2009


Hi Jack,

Maybe this helps.

#  make some data

set.seed(123)
condition <- factor(rep(c("a","b"), each = 5))
score <- rnorm(10);
lg <- data.frame(condition, score)

# Carry out commands

a <- subset(lg,condition=="a")["score"]
b <- subset(lg,condition=="b")["score"]

t.test(a,b,paired=TRUE)

#Error in `[.data.frame`(y, yok) : undefined columns selected

# a and b are still data frames

#So this works. We must refer to score, which is being compared.

t.test(a$score,b$score,paired=TRUE)


a=a[,1]
b=b[,1]

# This now works because a and b are vectors
# so we don't need $ to access score

t.test(a,b, paired=TRUE)

Regards,

Juliet




More information about the R-help mailing list