[R] How to repeat 2 functions in succession for 400 times? (microarray data)

David Winsemius dwinsemius at comcast.net
Sat May 11 20:31:13 CEST 2013


On May 11, 2013, at 9:21 AM, arun wrote:

> Hi,
> May be this helps:
> 
>  set.seed(24)
>  mydata4<- as.data.frame(matrix(sample(1:100,10*38,replace=TRUE),ncol=38)) 
>  dim(mydata4)
> #[1] 10 38
>  library(matrixStats)
> res<-do.call(cbind,lapply(1:400, function(i) {permutation<-sample(mydata4); (rowMeans(permutation[,1:27])-rowMeans(permutation[,28:38]))/(rowSds(permutation[,1:27])+rowSds(permutation[,28:38]))} ))
>  dim(res)
> #[1]  10 400
> 
> 
> A.K.
> 
>> I want to do permutation test and then get a PGC score 400 times on mydata4 (microarray data) 
>> 
>> I use 2 functions as below: 
>> 1. permutation<-sample(mydata4) 
>> 2. PGC <- (rowMeans(permutation[ ,1:27]) - rowMeans(permutation[ 
> ,28:38]))/ (rowSds(permutation [,1:27]) + rowSds(permutation [,28:38])) 
>> 
>> What should I do to repeat these 2 functions in succession for 
> 400 times and combine (cbind?) the 400 PGC score for the 7129 genes in 
> one file? 

Couldn't that just be:

fourPGCs <- replicate(400, {  permutation<-sample(mydata4) 
 PGC <- (rowMeans(permutation[ ,1:27]) - 
                 rowMeans( permutation[ ,28:38]))/
                (rowSds( permutation [,1:27]) + rowSds( permutation [,28:38]))
                           }

--

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list