title: R/Power-Query: Replace value with matching
body: <p>I am trying to cleaning up some data in a huge dataset.
  One column holds values for the Sales aamount. Example values could be like those:</p>
  
  <h1>Clean Data:</h1>
  
  <blockquote>
    <p><code>Sales Potential</code></p>
    
    <p><code>230</code></p>
    
    <p><code>120</code></p>
    
    <p><code>300</code></p>
  </blockquote>
  
  <p>However, at some points there appear something like this:</p>
  
  <h1>Dirty Data</h1>
  
  <blockquote>
    <p><code>0, 0, 0, 0, 0</code></p>
    
    <p><code>4, 0, 0, 0</code></p>
    
    <p><code>0, 0, 480</code></p>
    
    <p><code>0, 200, 0</code></p>
  </blockquote>
  
  <p>In the first case of the dirty data the cell shoul only contains a zero: <code>0</code>
  In all other cases I would like to extract, if there is any non-zero number, this number and replace the cell with this value or add a new cleanded-column.</p>
  
  <p>So the dirty data cleaned up:</p>
  
  <h1>Cleaned Data:</h1>
  
  <blockquote>
    <p><code>0</code></p>
    
    <p><code>4</code></p>
    
    <p><code>480</code></p>
    
    <p><code>200</code></p>
  </blockquote>
  
  <p>My approach was using RegExpressions in <code>R</code> as I am loading the data into Power-BI using Power-Query.
  I tried to find a pattern where I extract the value I am looking for and place it in a new column. However, my resutls looks like nothing. 
  Is there maybe a much simpler approach to achieve this in <code>R</code>?</p>
  
  <p>Code so far:
  <code>
  library(stringr)
  OutputRegEx &lt;- data.frame(MyDataset)
  Splitter = function(x) substr(str_extract(x,'[1-9]'),1,7)
  OutputRegEx[["RegExAuswertung"]] &lt;- apply(OutputRegEx[43],1, function(x) Splitter(x) )
  </code></p>