 <p>A regular expression substitution will do it. Look at the gsub() function.</p> <p>This gives you what you want (it removes any instance of '[' or ']'):</p> <pre><code>gsub("\\[|\\]", "", n) </code></pre>