title: R: Remove substring within string
body: <p>Is there an elegant way to remove a sub-string within a string based on the index of the characters?</p>
  
  <p>Here is how I do it now:</p>
  
  <pre><code># My data
  mystring &lt;- "Hello, how are {you} doing?"
  index_of_substring &lt;- c(16,20)
  
  # Pasting two substrings
  mystring_no_substring &lt;- paste0(substr(mystring, 1, index_of_substring[1]-1), substr(mystring, index_of_substring[2]+1, nchar(mystring)))
  
  # Cleaning extra spaces
  mystring_no_substring &lt;- gsub("  ", " ", mystring_no_substring)
  </code></pre>
  
  <p>I could of course write this up to a general function, but I was just wondering if there was an elegant solution out there, e.g. to substitute an index in a string with nothing or another word.</p>
  
  <p>Note: This is not a regex question.</p>