title: Removing duplicate words in a string in R
body: <p>Just to help someone who's just voluntarily removed their question, following a request for code he tried and other comments. Let's assume they tried something like this: </p>
  
  <pre class="lang-r prettyprint-override"><code>str &lt;- "How do I best try and try and try and find a way to to improve this code?"
  d &lt;- unlist(strsplit(str, split=" "))
  paste(d[-which(duplicated(d))], collapse = ' ')
  </code></pre>
  
  <p>and wanted to learn a better way. So what is the best way to remove a duplicate word from the string?</p>