Replace characters in column names gsub

前端 未结 2 1570
面向向阳花
面向向阳花 2020-12-15 07:50

I am reading in a bunch of CSVs that have stuff like \"sales - thousands\" in the title and come into R as \"sales...thousands\". I\'d like to use a regular expression (or o

相关标签:
2条回答
  • 2020-12-15 08:17

    Rich Scriven had the answer:

    Define

    colClean <- function(x){ colnames(x) <- gsub("\\.\\.+", ".", colnames(x)); x } 
    

    and then do

    a <- colClean(a) 
    

    to update a

    0 讨论(0)
  • 2020-12-15 08:29
    names(a) <- gsub(x = names(a), pattern = "\\.", replacement = "#")  
    

    you can use gsub function to replace . with another special character like #.

    0 讨论(0)
提交回复
热议问题