Reformarring complex factor vector with comma separation after thousand
<p>I would like to reformat a factor vector so the figures that it contains have a thousand separator. The vector contains integer and real number without any particular rule with respect to the values or order.</p>

<h1>Data</h1>

<p>In particular, I'm working with a vector <code>vec</code> similar to the one generated below:</p>

<pre><code>content &lt;- c("0 - 100", "0 - 100", "0 - 100", "0 - 100",
             "150.22 - 170.33",
             "1000 - 2000","1000 - 2000", "1000 - 2000", "1000 - 2000", 
             "7000 - 10000", "7000 - 10000", "7000 - 10000", "7000 - 10000",
             "7000 - 10000", "1000000 - 22000000", "1000000 - 22000000", 
             "1000000 - 22000000",
             "44000000 - 66000000.8989898989")

vec &lt;- factor(x = content, levels = unique(content))
</code></pre>

<h1>Desired results</h1>

<p>My ambition is to reformat this vector so the figures contain the <em>Excel-like</em> <strong>1,000</strong> separataor, as in the example below:</p>

<blockquote>
  <p>100.00 
  1,000.00<br>
  1,000,000.00<br>
  1,000,000.56<br>
  24,564,000,000.56</p>
</blockquote>

<hr>

<h1>Tried approach</h1>

<p>I was thinking of making use of the <code>gsubfn</code> and a proto object that would pass the digit. Then maybe createing another proto object with 3 digits and replacing. As suggested in the code below:</p>

<pre><code>gsubfn(pattern = "[0-9][0-9][0-9]", replacement = ~paste0(x, ','), 
       x = as.character(vec))
</code></pre>

<p>This works only partuially as comma is insterted in:</p>

<blockquote>
  <p>"150,.22 - 170,.33"</p>
</blockquote>

<p>which obviously is wrong. I also had to convert the character vector to factor. Consquently, my question boils down to two elements:</p>

<ul>
<li>How can I work around the comma issue?</li>
<li><strong>How can I maintain the original structure of the factor?</strong> - <em>I need to have a factor vector ordered in the same manner as the original one but with commas in right places.</em></li>
</ul>