Probably not the most efficient, but here's one way that builds on your initial effort.
Your example data:
experimentName <- paste(rep("name",20), c(1:20), sep="")
experimentAnno1 <- rep(paste(rep("anno",5), c(1:5), sep=""), 4)
a1 <- rnorm(n=20, mean=10, sd=5)
a2 <- rnorm(n=20, mean=11, sd=5)
a3 <- rnorm(n=20, mean=12, sd=5)
b1 <- rnorm(n=20, mean=20, sd=5)
b2 <- rnorm(n=20, mean=21, sd=5)
b3 <- rnorm(n=20, mean=19, sd=5)
I use data.frame
rather than cbind
so we can keep the numbers as numerics (cbind
coerces them to character)
# sampledata <- cbind(experimentName, experimentAnno1, a1,a2,a3,b1,b2,b3)
sampledata <- data.frame(experimentName, experimentAnno1, a1,a2,a3,b1,b2,b3)
Seems like your goal is to within each row, test set of a1, a2, a3, against set of b1, b2, b3
Here are some lapply
functions that get those values:
sampledata$pvalue <- sapply(1:nrow(sampledata), function(i) t.test(sampledata[i,c("a1", "a2", "a3")], sampledata[i,c("b1", "b2", "b3")])$p.value)
sampledata$LoConf <- sapply(1:nrow(sampledata), function(i) t.test(sampledata[i,c("a1", "a2", "a3")], sampledata[i,c("b1", "b2", "b3")])$conf.int[1])
sampledata$UpConf <- sapply(1:nrow(sampledata), function(i) t.test(sampledata[i,c("a1", "a2", "a3")], sampledata[i,c("b1", "b2", "b3")])$conf.int[2])