Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>UPDATED BELOW TO SHOW PARALLEL PROCESSING - ABOUT A 60% SAVING</strong></p> <p>Using <code>apply()</code> might not be quick enough for you. Here's how to do it, though. Will have a think about performance since this example (1M output correlations in 1000x1000 grid) takes over a minute on laptop. </p> <pre><code>miRdf=matrix(rnorm(13000,10,1),ncol=13) mRNAdf=matrix(rnorm(13000,10,1),ncol=13) miRdf[,1]&lt;-1:nrow(miRdf) # using column 1 as indices since they're not in the calc. mRNAdf[,1]&lt;-1:nrow(mRNAdf) corRow&lt;-function(y){ apply(miRdf,1,function(x)cor(as.numeric(x[2:13]), as.numeric(mRNAdf[y,2:13]), use ="complete.obs")) } system.time(apply(mRNAdf,1,function(x)corRow(x[1]))) # user system elapsed # 72.94 0.00 73.39 </code></pre> <p>And with <code>parallel::parApply</code> on a 4 core Win64 laptop</p> <pre><code>require(parallel) ## Library to allow parallel processing miRdf=matrix(rnorm(13000,10,1),ncol=13) mRNAdf=matrix(rnorm(13000,10,1),ncol=13) miRdf[,1]&lt;-1:nrow(miRdf) # using column 1 as indices since they're not in the calc. mRNAdf[,1]&lt;-1:nrow(mRNAdf) corRow&lt;-function(y){ apply(miRdf,1,function(x)cor(as.numeric(x[2:13]), as.numeric(mRNAdf[y,2:13]), use ="complete.obs")) } # Make a cluster from all available cores cl=makeCluster(detectCores()) # Use clusterExport() to distribute the function and data.frames needed in the apply() call clusterExport(cl,c("corRow","miRdf","mRNAdf")) # time the call system.time(parApply(cl,mRNAdf,1,function(x)corRow(x[[1]]))) # Stop the cluster stopCluster(cl) # time the call without clustering system.time(apply(mRNAdf,1,function(x)corRow(x[[1]]))) ## WITH CLUSTER (4) user system elapsed 0.04 0.03 29.94 ## WITHOUT CLUSTER user system elapsed 73.96 0.00 74.46 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload