<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284635#M21972</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;The R function &lt;CODE&gt;caret::findCorrelation&lt;/CODE&gt; searches a correlation matrix and returns a vector of integers corresponding to variables which, if removed, would reduce pair-wise correlations among the remaining variables. Here is the R code for this function:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; FALSE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; names &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; FALSE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; exact &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; ncol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;100&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;names &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;is&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colnames&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"'x' must have column names when `names = TRUE`"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;exact&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; findCorrelation_exact&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;else&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelation_fast&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;names&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; colnames&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;And the function &lt;CODE&gt;findCorrelation_fast&lt;/CODE&gt;, which is the one I am interested in (with optional arguments removed):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;findCorrelation_fast &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;90&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;any&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(!&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;complete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;cases&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; stop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"The correlation matrix has some missing values."&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; colMeans&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;numeric&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;factor&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lower&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;tri&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; diag &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; TRUE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; NA&amp;nbsp; combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; which&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; colsToCheck &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; ceiling&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;/&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; nrow&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToCheck &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;%%&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; nrow&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; colsToDiscard &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;rowsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToDiscard &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;!&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToDiscard&amp;nbsp;&amp;nbsp; deletecol &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; c&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToDiscard&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;],&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;rowsToDiscard&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;])&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; deletecol &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; unique&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;deletecol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; deletecol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;I am writing a function that emulates the intent of this function in Python 3 with help from pandas. My implementation contains a nested &lt;CODE&gt;for&lt;/CODE&gt; loop, which I understand is far from the most efficient way to achieve the desired result. The original R function does the job without any looping.&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My two questions are:&lt;/P&gt;&lt;OL style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em 30px;"&gt;&lt;LI style="border: 0px; margin: 0px 0px 0.5em;"&gt;Based on my implementation below, is there a Pythonic way to replace the nested &lt;CODE&gt;for&lt;/CODE&gt; loop with a vectorised implementation?&lt;/LI&gt;&lt;LI style="border: 0px;"&gt;Related to (1), the R function &lt;CODE&gt;findCorrelation_fast&lt;/CODE&gt; uses the line &lt;CODE&gt;averageCorr &amp;lt;- as.numeric(as.factor(averageCorr))&lt;/CODE&gt;. This construction seems both very alien to me and also crucial to the success of the loopless R implementation. Can anyone shed any light on what this line is doing? My intuition tells me that it is being incredibly clever and leveraging some unique behaviour of R.&lt;/LI&gt;&lt;/OL&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My Python implementation and an example of its usage:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; numpy &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pandas &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pd &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# calculate pair-wise correlations&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;def&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.8&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;### search correlation matrix and identify pairs that if removed would reduce pair-wise correlations&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# args:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# corrmat: a correlation matrix&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# cutoff: pairwise absolute correlation cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# returns:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# variables to removed&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;!=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;columns&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;return&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Correlation matrix is not square'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;().&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;mean&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;axis &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# set lower triangle and diagonal of correlation matrix to NA&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; corrmat &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;where&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;triu&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;ones&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;shape&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)).&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;astype&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;bool&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;values&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;arange&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))]*&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;2&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;None&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# where a pairwise correlation is greater than the cutoff value, check whether mean abs.corr of a or b is greater and cut it&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; list&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;()&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; col &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; range&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;columns&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; row &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; range&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;append&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;else&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;append&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; list&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;set&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;return&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# generate some data&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pd&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;DataFrame&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;random&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;randn&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;50&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;25&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# demonstrate usage of function&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(),&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.01&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;#set v.low cutoff as data is uncorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Columns to be removed:'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;uncorrelated &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;drop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;index&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;],&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; axis &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; inplace &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;False&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Uncorrelated variables:'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;uncorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)

&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:46:09 GMT</pubDate>
    <dc:creator>TejuNC</dc:creator>
    <dc:date>2021-12-11T13:46:09Z</dc:date>
    <item>
      <title>Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation</title>
      <link>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284635#M21972</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;The R function &lt;CODE&gt;caret::findCorrelation&lt;/CODE&gt; searches a correlation matrix and returns a vector of integers corresponding to variables which, if removed, would reduce pair-wise correlations among the remaining variables. Here is the R code for this function:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.9&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; FALSE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; names &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; FALSE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; exact &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; ncol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;100&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;names &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;is&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;null&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colnames&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"'x' must have column names when `names = TRUE`"&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;exact&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; findCorrelation_exact&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;else&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelation_fast&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; verbose&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;names&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; colnames&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;out&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;And the function &lt;CODE&gt;findCorrelation_fast&lt;/CODE&gt;, which is the one I am interested in (with optional arguments removed):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;findCorrelation_fast &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;function&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;90&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;{&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;any&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(!&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;complete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;cases&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; stop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;"The correlation matrix has some missing values."&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; colMeans&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;numeric&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;factor&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;lower&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;tri&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; diag &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; TRUE&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; NA&amp;nbsp; combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; which&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; colsToCheck &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; ceiling&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;/&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; nrow&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToCheck &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; combsAboveCutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;%%&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; nrow&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;x&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp; colsToDiscard &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;rowsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToDiscard &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;!&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToDiscard&amp;nbsp;&amp;nbsp; deletecol &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; c&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;colsToDiscard&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;],&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; rowsToCheck&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;rowsToDiscard&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;])&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; deletecol &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;lt;-&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; unique&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;deletecol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; deletecol&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;}&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;I am writing a function that emulates the intent of this function in Python 3 with help from pandas. My implementation contains a nested &lt;CODE&gt;for&lt;/CODE&gt; loop, which I understand is far from the most efficient way to achieve the desired result. The original R function does the job without any looping.&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My two questions are:&lt;/P&gt;&lt;OL style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em 30px;"&gt;&lt;LI style="border: 0px; margin: 0px 0px 0.5em;"&gt;Based on my implementation below, is there a Pythonic way to replace the nested &lt;CODE&gt;for&lt;/CODE&gt; loop with a vectorised implementation?&lt;/LI&gt;&lt;LI style="border: 0px;"&gt;Related to (1), the R function &lt;CODE&gt;findCorrelation_fast&lt;/CODE&gt; uses the line &lt;CODE&gt;averageCorr &amp;lt;- as.numeric(as.factor(averageCorr))&lt;/CODE&gt;. This construction seems both very alien to me and also crucial to the success of the loopless R implementation. Can anyone shed any light on what this line is doing? My intuition tells me that it is being incredibly clever and leveraging some unique behaviour of R.&lt;/LI&gt;&lt;/OL&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My Python implementation and an example of its usage:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; numpy &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pandas &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;as&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pd &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# calculate pair-wise correlations&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;def&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.8&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;### search correlation matrix and identify pairs that if removed would reduce pair-wise correlations&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# args:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# corrmat: a correlation matrix&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# cutoff: pairwise absolute correlation cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# returns:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# variables to removed&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;!=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;columns&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;return&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Correlation matrix is not square'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; averageCorr &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;abs&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;().&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;mean&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;axis &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# set lower triangle and diagonal of correlation matrix to NA&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; corrmat &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;where&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;triu&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;ones&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;shape&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)).&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;astype&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;bool&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;values&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;arange&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))]*&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;2&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;None&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# where a pairwise correlation is greater than the cutoff value, check whether mean abs.corr of a or b is greater and cut it&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; list&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;()&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; col &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; range&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;columns&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;for&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; row &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;in&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; range&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; len&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corrmat&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;if&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; averageCorr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;iloc&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;]):&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;append&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;row&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;else&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;:&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;append&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;col&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; list&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;set&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;to_delete&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;return&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; to_delete &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# generate some data&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; pd&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;"&gt;DataFrame&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;np&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;random&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;randn&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;50&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;25&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;))&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;# demonstrate usage of function&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; findCorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;corr&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(),&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; cutoff &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;0.01&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"&gt;#set v.low cutoff as data is uncorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Columns to be removed:'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;uncorrelated &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;drop&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;df&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;index&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;[&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;removeCols&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;],&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; axis &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;1&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; inplace &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;False&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;"&gt;'Uncorrelated variables:'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-size: 13px;"&gt;print&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;uncorrelated&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"&gt;)

&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:46:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284635#M21972</guid>
      <dc:creator>TejuNC</dc:creator>
      <dc:date>2021-12-11T13:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation</title>
      <link>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284636#M21973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you reformat your code so it can be examined&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jan 2017 19:01:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284636#M21973</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-01-20T19:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation</title>
      <link>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284637#M21974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;The R function &lt;/SPAN&gt;&lt;CODE style="color: #242729; border: 0px; font-size: 13px; padding: 1px 5px;"&gt;caret::findCorrelation&lt;/CODE&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt; searches a correlation matrix and returns a vector of integers corresponding to variables which, if removed, would reduce pair-wise correlations among the remaining variables. Here is the R code for this function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;SPAN style="color: #242729; background-color: #ffffff;"&gt;function (x, cutoff = 0.9, verbose = FALSE, names = FALSE, exact = ncol(x) &amp;lt; &lt;BR /&gt;100) &lt;BR /&gt; {&lt;BR /&gt; if (names &amp;amp; is.null(colnames(x))) &lt;BR /&gt; stop("'x' must have column names when `names = TRUE`")&lt;BR /&gt; out &amp;lt;- if (exact) &lt;BR /&gt; findCorrelation_exact(x = x, cutoff = cutoff, verbose = verbose)&lt;BR /&gt; else findCorrelation_fast(x = x, cutoff = cutoff, verbose = verbose)&lt;BR /&gt; out&lt;BR /&gt; if (names) &lt;BR /&gt; out &amp;lt;- colnames(x)[out]&lt;BR /&gt; out&lt;BR /&gt;}&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="border: 0px; margin: 0px 0px 1em;"&gt;And the function &lt;CODE style="border: 0px; font-size: 13px; padding: 1px 5px;"&gt;findCorrelation_fast&lt;/CODE&gt;, which is the one I am interested in (with optional arguments removed):&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;findCorrelation_fast &amp;lt;- function(x, cutoff = .90)&lt;BR /&gt;{&lt;BR /&gt; if(any(!complete.cases(x)))&lt;BR /&gt; stop("The correlation matrix has some missing values.")&lt;BR /&gt; averageCorr &amp;lt;- colMeans(abs(x))&lt;BR /&gt; averageCorr &amp;lt;- as.numeric(as.factor(averageCorr))&lt;BR /&gt; x[lower.tri(x, diag = TRUE)] &amp;lt;- NA&lt;BR /&gt; combsAboveCutoff &amp;lt;- which(abs(x) &amp;gt; cutoff)&lt;/P&gt;&lt;P&gt;colsToCheck &amp;lt;- ceiling(combsAboveCutoff / nrow(x))&lt;BR /&gt; rowsToCheck &amp;lt;- combsAboveCutoff %% nrow(x)&lt;/P&gt;&lt;P&gt;colsToDiscard &amp;lt;- averageCorr[colsToCheck] &amp;gt; averageCorr[rowsToCheck]&lt;BR /&gt; rowsToDiscard &amp;lt;- !colsToDiscard&lt;/P&gt;&lt;P&gt;deletecol &amp;lt;- c(colsToCheck[colsToDiscard], rowsToCheck[rowsToDiscard])&lt;BR /&gt; deletecol &amp;lt;- unique(deletecol)&lt;BR /&gt; deletecol&lt;BR /&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;I am writing a function that emulates the intent of this function in Python 3 with help from pandas. My implementation contains a nested &lt;CODE style="border: 0px; font-size: 13px; padding: 1px 5px;"&gt;for&lt;/CODE&gt; loop, which I understand is far from the most efficient way to achieve the desired result. The original R function does the job without any looping.&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My two questions are:&lt;/P&gt;&lt;OL style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em 30px;"&gt;&lt;LI style="border: 0px; margin: 0px 0px 0.5em;"&gt;Based on my implementation below, is there a Pythonic way to replace the nested &lt;CODE style="border: 0px; font-size: 13px; padding: 1px 5px;"&gt;for&lt;/CODE&gt; loop with a vectorised implementation?&lt;/LI&gt;&lt;LI style="border: 0px;"&gt;Related to (1), the R function &lt;CODE style="border: 0px; font-size: 13px; padding: 1px 5px;"&gt;findCorrelation_fast&lt;/CODE&gt; uses the line &lt;CODE style="border: 0px; font-size: 13px; padding: 1px 5px;"&gt;averageCorr &amp;lt;- as.numeric(as.factor(averageCorr))&lt;/CODE&gt;. This construction seems both very alien to me and also crucial to the success of the loopless R implementation. Can anyone shed any light on what this line is doing? My intuition tells me that it is being incredibly clever and leveraging some unique behaviour of R.&lt;/LI&gt;&lt;/OL&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;My Python implementation and an example of its usage:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;import numpy as np&lt;BR /&gt;import pandas as pd&lt;/P&gt;&lt;P&gt;# calculate pair-wise correlations&lt;/P&gt;&lt;P&gt;def findCorrelated(corrmat, cutoff = 0.8):&lt;/P&gt;&lt;P&gt;### search correlation matrix and identify pairs that if removed would reduce pair-wise correlations&lt;BR /&gt;# args:&lt;BR /&gt; # corrmat: a correlation matrix&lt;BR /&gt; # cutoff: pairwise absolute correlation cutoff&lt;BR /&gt;# returns:&lt;BR /&gt; # variables to removed&lt;/P&gt;&lt;P&gt;if(len(corrmat) != len(corrmat.columns)) : return 'Correlation matrix is not square'&lt;BR /&gt; averageCorr = corrmat.abs().mean(axis = 1)&lt;/P&gt;&lt;P&gt;# set lower triangle and diagonal of correlation matrix to NA&lt;BR /&gt; corrmat = corrmat.where(np.triu(np.ones(corrmat.shape)).astype(np.bool))&lt;BR /&gt; corrmat.values[[np.arange(len(corrmat))]*2] = None&lt;/P&gt;&lt;P&gt;# where a pairwise correlation is greater than the cutoff value, check whether mean abs.corr of a or b is greater and cut it&lt;BR /&gt; to_delete = list()&lt;BR /&gt; for col in range(0, len(corrmat.columns)):&lt;BR /&gt; for row in range(0, len(corrmat)):&lt;BR /&gt; if(corrmat.iloc[row, col] &amp;gt; cutoff):&lt;BR /&gt; if(averageCorr.iloc[row] &amp;gt; averageCorr.iloc[col]): to_delete.append(row)&lt;BR /&gt; else: to_delete.append(col)&lt;/P&gt;&lt;P&gt;to_delete = list(set(to_delete))&lt;/P&gt;&lt;P&gt;return to_delete&lt;/P&gt;&lt;P&gt;# generate some data&lt;BR /&gt;df = pd.DataFrame(np.random.randn(50,25))&lt;/P&gt;&lt;P&gt;# demonstrate usage of function &lt;BR /&gt;removeCols = findCorrelated(df.corr(), cutoff = 0.01) #set v.low cutoff as data is uncorrelated&lt;BR /&gt;print('Columns to be removed:')&lt;BR /&gt;print(removeCols)&lt;BR /&gt;uncorrelated = df.drop(df.index[removeCols], axis =1, inplace = False)&lt;BR /&gt;print('Uncorrelated variables:')&lt;BR /&gt;print(uncorrelated)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Hope you can see clearly now...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Jan 2017 06:11:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284637#M21974</guid>
      <dc:creator>TejuNC</dc:creator>
      <dc:date>2017-01-21T06:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation</title>
      <link>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284638#M21975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The indentation is completely off...&lt;/P&gt;&lt;P&gt;EDIT &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can follow up over on Stack Exchange... the code is formatted properly there&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://stackoverflow.com/questions/41761332/translate-r-function-caretfindcorrelation-to-python-3-via-pandas-using-vectori" title="http://stackoverflow.com/questions/41761332/translate-r-function-caretfindcorrelation-to-python-3-via-pandas-using-vectori"&gt;Translate R function caret::findCorrelation to Python 3 via Pandas using vectorisation - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;did you recopy the original&amp;nbsp;code and paste it wil the python syntax highligher?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;It appears you are using np.triu to manage the correlation matrix but it is hard to follow,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;have you looked at the np.corrcoeff and np.cov in numpy (np). &amp;nbsp;inline help. &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;&lt;A class="link-titled" href="https://github.com/numpy/numpy/blob/32ade3a75de147027c477a08d427d6f64603edfd/numpy/lib/function_base.py#L2921" title="https://github.com/numpy/numpy/blob/32ade3a75de147027c477a08d427d6f64603edfd/numpy/lib/function_base.py#L2921"&gt;numpy/function_base.py at 32ade3a75de147027c477a08d427d6f64603edfd · numpy/numpy · GitHub&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;Also np.vectorize is a helper to reduce the need for loops. &amp;nbsp;I am not sure why you need to flip this all out to pandas, unless your resultant array ends up being an object dtype.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;Perhaps you could show an input array as an example and a desired output array to see if findcorrelation fast can be implemented within numpy directly&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Jan 2017 08:12:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/translate-r-function-caret-findcorrelation-to/m-p/284638#M21975</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-01-21T08:12:46Z</dc:date>
    </item>
  </channel>
</rss>

