Search code examples
rquotation-marks

How to remove unnecessary single quotation marks (') from column names in a R data frame?


unfortunately I have got colnames, which all have additional single quotation marks like here:

x <- data.frame(c(11,21,31),c(12,22,32),c(13,23,33))
colnames(x) <- c("'A'","'B'","'C'")

So my question is, if I can get rid of those "'" for my entire data frame? Preferably not retyping the colnames, and using tidyR code? Thanks!


Solution

  • library(stringr)
    
    colnames(x) <- str_remove_all(colnames(x), "'")
    

    That should do it

    library(dplyr)
    library(stringr)
        x %>% 
           rename_all(~str_remove_all(., "'"))
    

    If you want a pipe