I'm trying to remove [ and ] characters from a string in R, I have tried the following code:
gsub("[]", "", p1)
but this doesn't work.
I'm trying to remove [ and ] characters from a string in R, I have tried the following code:
gsub("[]", "", p1)
but this doesn't work.
It doesn't work because []
indicates an invalid character class in which it should throw an error saying "invalid regular expression", you need to put together a complete character class.
gsub('[][]', '', p1)
I would recommend reading up on Character Classes or Character Sets ...
You can try:
x = 'mycharac[ter]'
gsub('\\[|\\]','',x)
#[1] "mycharacter"