Created
March 20, 2016 22:33
-
-
Save nishimoto/ebe7cd16dbeed0453106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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