Remove square brackets from a string vector

后端 未结 4 1880
逝去的感伤
逝去的感伤 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:47

    If working within tidyverse:

    library(tidyverse); library(stringr)
    
    n = c("[Dave]", "[Tony]", "[Sara]")
    
    n %>% str_replace_all("\\[|\\]", "")
    [1] "Dave" "Tony" "Sara"
    

提交回复
热议问题