Skip to content

Instantly share code, notes, and snippets.

@nishimoto
Created March 20, 2016 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishimoto/ebe7cd16dbeed0453106 to your computer and use it in GitHub Desktop.
Save nishimoto/ebe7cd16dbeed0453106 to your computer and use it in GitHub Desktop.
# 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