title: Extracting left side and right side of a string with operators in r
body: <p>I have a dataframe contains formulas from a random forest model ( the tree gathered by using getTree and formulas obtained by user defined function).</p>
  <p>Example Input:</p>
  <pre><code>'%!in%' &lt;- function(x,y)!('%in%'(x,y))
  
  example &lt;- data.frame(formulas = c(&quot;train %&gt;% filter( balance &gt; 599.5 &amp; balance &lt; 605.5 &amp; 
                                                        contact %!in% c( 'cellular', 'telephone' ) &amp; balance &gt; 566.5 &amp; 
                                                        job_group1 %!in% c( 'services' ) &amp; 
                                                        education %in% c( 'primary' ) &amp; month_group1 %in% c( 'jun' ) &amp; 
                                                        education %!in% c( 'tertiary' ) &amp; 
                                                        job_group1 %!in% c( 'blue-collar' ) )&quot;,
                                     &quot;train %&gt;% filter( day &gt; 9.5 &amp; 
                                                        month_group1 %!in% c( 'apr', 'feb', 'jan', 'nov', 'oct' ) &amp; 
                                                        balance &gt; 443.5 &amp; balance &lt; 597 &amp; balance &lt; 650.5 &amp; 
                                                        job_group1 %!in% c( 'admin.', 'blue-collar', 'management', 'retired' ) &amp; 
                                                        month_group1 %!in% c( 'jul' ) &amp; 
                                                        contact %in% c( 'cellular', 'telephone' ) &amp;
                                                        month_group1 %!in% c( 'aug' ) &amp; housing %in% c( 'no' ) &amp; 
                                                        education %!in% c( 'secondary' ) &amp; 
                                                        education %!in% c( 'tertiary' ) &amp;
                                                        month_group1 %!in% c( 'jun', 'may' ) )&quot; ),
                        cluster = c(&quot;1&quot;,&quot;2&quot;) )                                                                                    
  </code></pre>
  <p>My expectation is extracting left side, right side of the operator, the operator and cluster name and save it into new dataframe.</p>
  <p>Expected Output</p>
  <pre><code>desired &lt;- data.frame( LHS = c(&quot;balance&quot;,&quot;balance&quot;,&quot;contact&quot;,&quot;balance&quot;,&quot;job_group1&quot;,
                                 &quot;education&quot;,&quot;month_group1&quot;, &quot;education&quot;,&quot;job_group1&quot;,
                                 &quot;day&quot;,&quot;month_group1&quot;,&quot;balance&quot;,&quot;balance&quot;,&quot;balance&quot;,
                                 &quot;job_group1&quot;,&quot;month_group1&quot;,&quot;contact&quot;,&quot;month_group1&quot;,&quot;housing&quot;,
                                 &quot;education&quot;,&quot;education&quot;,&quot;month_group1&quot;),
                         RHS = c(599.5,605.5,c(&quot;cellular, telephone&quot;),566.5,c(&quot;services&quot;),
                                 c(&quot;primary&quot;),c(&quot;jun&quot;), c(&quot;tertiary&quot;),c(&quot;blue-collar&quot;),
                                 9.5,c(&quot;apr,feb,jan,nov,oct&quot;),443.5,597,650.5,c(&quot;admin.,blue-collar,
                                 management,retired&quot;), c(&quot;jul&quot;), c(&quot;cellular,telephone&quot;), c(&quot;aug&quot;),
                                 c(&quot;no&quot;),c(&quot;secondary&quot;),c(&quot;tertiary&quot;),c(&quot;jun,may&quot;)),
                         Operator = c(&quot;&gt;&quot;, &quot;&lt;&quot;, &quot;%!in%&quot;, &quot;&gt;&quot;, &quot;%!in%&quot;, &quot;%in%&quot;, &quot;%in%&quot;,
                                      &quot;%!in%&quot;, &quot;%!in%&quot;,&quot;&gt;&quot;, &quot;%!in%&quot;, &quot;&gt;&quot;, &quot;&lt;&quot;, &quot;&lt;&quot;, &quot;%!in%&quot;,
                                      &quot;%!in%&quot;, &quot;%in%&quot;, &quot;%!in%&quot;, &quot;%in%&quot;, &quot;%!in%&quot;, &quot;%!in%&quot;, &quot;%!in%&quot;),
                         cluster = c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2) )
  </code></pre>
  <p>I'm using R version 3.3.3 as the project requires it.</p>