title: Remove hyphen at the end of string in R
body: <p>I have a column of a dataframe in R like this:</p>
  <pre><code>names &lt;- data.frame(name=c(&quot;ABC&quot;, &quot;ABC-D&quot;, &quot;ABCD-&quot;))
  </code></pre>
  <p>I would like to remove the hyphen at the end of the strings while maintaining the hyphen in the middle of them. I've tried a few expressions like:</p>
  <pre><code>names$name &lt;- gsub(&quot;+-\\w&quot;, &quot;&quot;, names$name)
  # the desired output is &quot;ABC&quot;, &quot;ABC-D&quot;, and &quot;ABCD&quot;, respectively
  </code></pre>
  <p>While several combinations remove the hyphens entirely, I'm not sure how to specify the string boundary and the hyphen together.</p>
  <p>Thanks!</p>