# R语言 t检验多核并行运算 v1.2_ r语言 t检验

4066℃

#These two function are based on the package “multicore”
#It can be reduce your cost efficiently when you run t-test for bulk data
sc.t.test<-function(data)
{
if(!is.vector(data) & !is.matrix(data)) stop(“Need a vector or a matrix…”)
if(length(data) != floor(length(data)/2)*2) stop(“There is odd number…”)
if(is.vector(data))
{
k<-unlist(t.test(data[1:5],data[6:10])[3])
}
if(is.matrix(data))
{
k<-array(numeric())
for(i in 1:length(data[,1]))
{
k[i]<-unlist(t.test(data[i,1:5],data[i,6:10])[3])
}
}
return(k)
}
mc.t.test<-function(data,mc.core=parallel::detectCores())
{
p<-array(numeric())
k<-array(numeric())
mc.core<-ifelse(mc.core
for( i in 1:mc.core)
{
length<- ifelse(i==mc.core,(length(data[,1])-ceiling(length(data[,1])/mc.core)*(i-1)),(ceiling(length(data[,1])/mc.core)))
start<-ifelse(i==mc.core,ceiling(length(data[,1])/mc.core)*(i-1)+1,(i-1)*length+1)
end<-ifelse(i==mc.core,length(data[,1]),i*length)
if (end >= length(data[,1])) end = length(data[,1])
if (start >= length(data[,1])) start = length(data[,1])
if(start != end ) {p[i]<-parallel(sc.t.test(data[start:end,]))\$pid}else{p[i]<-parallel(sc.t.test(data[start,]))\$pid}
if(end == length(data[,1])) break
}
result<-unlist(collect(p))
attributes(result)<-NULL
return(result)
}

• 在线沟通，请点我在线咨询

• 咨询热线：
13261671783
客服qq：
3285157825