|
本帖最后由 genechip 于 2010-6-9 12:49 编辑
原始数据格式如下
> rowdata
case1 case2 case3 case4 d1 d2 d3 d4 d5
1 131.6050 288.4217 297.9130 294.2759 166.6447 323.0771 171.4527 310.9189 83.5828
2 158.2153 103.3708 132.1709 169.5547 138.6331 145.2714 124.1450 243.5407 306.1274
3 198.7473 173.5684 252.8740 180.0233 313.6674 240.7420 145.0514 230.9099 347.9528
4 14.4411 81.6446 58.7209 47.2538 58.2751 48.7055 54.4860 41.6889 8.9292
5 37.4716 109.1788 112.0269 125.6444 73.2163 77.8732 56.2856 160.9400 332.9519
t.test_pro<-function(path1,path2,n,classnumb=c(...)){
lili<-as.matrix(read.table(path1,header=T));
g<-as.numeric()
for(i in 1:n){
z<-rep(i,classnumb)
g<-c(g,z)
}
g1<-as.factor(g)
Pvalue<-list()
Tvalue<-list()
MEAN_value<-list()
kk<-data.frame()
for(i in 1:dim(lili)[1]){
data<-lili[i,]
result<-t.test(data~g)
Pvalue[]<-result[[3]]
Tvalue[]<-result[[1]]
MEAN_value[]<-result[[5]]
}
mean_1<-lapply(MEAN_value,function(x) x[1])
mean_2<-lapply(MEAN_value,function(x) x[2])
liliresult<-cbind(lili,as.numeric(Tvalue),as.numeric(Pvalue),as.numeric(mean_1),as.numeric(mean_2))
colnames(liliresult)<-c(colnames(lili),"Tvalue","Pvalue","Meanx_1","Meanx_2")
liliresult
write.table(liliresult,path2)
}
t.test_pro(path1="",path2="",n=2,classnumb=c(4,5))
其中path1是输入数据路径,path2是输出数据路径,n代表数据中两组样本,classnumb代表两组样本个体数目。
|
|