Remove square brackets from a string vector

后端 未结 4 1882
逝去的感伤
逝去的感伤 2020-12-03 10:21

I have a character vector in which each element is enclosed in brackets. I want to remove the brackets and just have the string.

So I tried:

n = c(\"         


        
4条回答
  •  甜味超标
    2020-12-03 10:45

    You could gsub out the brackets like so:

    n = c("[Dave]", "[Tony]", "[Sara]")
    
    gsub("\\[|\\]", "", n)
    [1] "Dave" "Tony" "Sara"
    

提交回复
热议问题