Skip to content
Prev 323379 / 398503 Next

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

Hi David,

Yes.
Both are similar in speed. 

set.seed(48)
?system.time({fourPGCs <- replicate(400, {? permutation<-sample(mydata4)
?PGC <- (rowMeans(permutation[ ,1:27]) -
???????????????? rowMeans( permutation[ ,28:38]))/
???????????????? (rowSds( permutation [,1:27]) + rowSds( permutation [,28:38]))
?????????????????????????? }
?)})
?# user? system elapsed 
?# 3.712?? 0.000?? 3.723 


?set.seed(48)
?system.time({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]))} )) })
# user? system elapsed 
#? 3.624?? 0.000?? 3.632 

?identical(fourPGCs,res)
#[1] TRUE
A.K.







----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>
Sent: Saturday, May 11, 2013 2:31 PM
Subject: Re: [R] How to repeat 2 functions in succession for 400 times? (microarray data)
On May 11, 2013, at 9:21 AM, arun wrote:

            
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