Replacing multiples of 10 in a dataset
<p>I have a problem which has proven pretty hard to solve. I have a dataset <code>D</code> were I want to replace all data points that can be written as y=x*10^n where x is an integer which is not larger than 10 (e.g. y=20,300,... but not 25, 375...). I want to replace these data points y with y-1. So for example I want 20 to become 19, 300 to become 299 etc.</p>

<p>For example say my dataset <code>D</code> is:</p>

<pre><code>D &lt;- c(20, 32, 200, 300.12, 40, 213, 60, 75)
</code></pre>

<p>Then I want my new dataset to be</p>

<pre><code>Dnew
[1]  19  32 199 300.12 39 213 59 75
</code></pre>

<p>I have tried many ways using the <code>gsub()</code> function but I can't make it work.</p>