Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Idea # 1: Why not:</p> <pre><code>Genedata$SPOCK1.202363_at_recode &lt;- factor( Genedata$SPOCK1.202363_at &lt;= 8.2244399999999995, labels=c("0", "1") ) </code></pre> <p>That way you don't need to process the inequality twice. You could skip the <code>factor</code> call if you could accept it as a logical vector:</p> <pre><code>Genedata$SPOCK1.202363_at_recode &lt;- Genedata$SPOCK1.202363_at &lt;= 8.2244399999999995 </code></pre> <p>Idea #2: This would surely be faster for multiple rows for a matrix named "X":</p> <pre><code>X &lt;- (X &lt; rep( colMeans(X), each=nrow(X) ) ) </code></pre> <p>You could do it like this:</p> <pre><code>Genedata[ , cols_to_process] &lt;- ( Genedata[ , cols_to_process] &lt; rep( cutoff_vector, each=nrow(Genedata[ , cols_to_process]) ) ) </code></pre> <p>Notice that this is essentially what @flodel's comment was suggesting, because he was converting columns to rows and depending on argument recycling, and then restoring the original structure. Regarding the parallelization option, I don't think this fairly small dataset warrants the effort. This took about 3 minutes on a 5 year-old machine:</p> <pre><code> dfrm &lt;- data.frame(matrix(rnorm(43000*170), 170) ) cutoff &lt;- rnorm(43000, 0, 0.2) system.time( dfrm[ , 1:43000] &lt;- ( dfrm[ , 1:43000] &lt; rep( cutoff, each=170 ) ) ) # user system elapsed #129.052 57.449 185.660 </code></pre> <p>Converting to a matrix might speed this up considerably:</p> <pre><code> mtx &lt;- matrix(rnorm(43000*170), 170) system.time( mtx &lt;- t(1*(t(mtx) &gt; cutoff) ) ) # user system elapsed # 0.226 0.133 0.358 mtx &lt;- matrix(rnorm(43000*170), 170) system.time( mtx[ , 1:43000] &lt;- ( mtx[ , 1:43000] &lt; rep( cutoff, each=170 ) ) ) # user system elapsed # 0.852 0.001 0.849 #Now do it all at once............ system.time( mtx &lt;- mtx &lt; rep( cutoff, each=170 ) ) # user system elapsed #0.095 0.000 0.094 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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