Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# dataの準備
data <- cbind(c(1,2,3),c(4,5,6),c(7,8,9),c(10,11,12),c(8,5,7))
rownames(data) <- c("A","B","C")
colnames(data) <- c("Sample1","Sample2","Sample3","Sample4","Sample5")
# dataにメタデータを付加
data <- rbind(data,c(1,1,2,2,2))
rownames(data) <- c("A","B","C","metadata1")
# すべての行について、metadata1に従って検定する
# (つまりSample1と2 VS Sample3と4と5 で検定する)
group1 <- data["metadata1",]==1
group2 <- data["metadata1",]==2
result <- apply(data[-nrow(data),], 1, function(x) t.test(x[group1],x[group2])$p.value)
write.table(result,file="result.tsv",sep="\t",col.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment