Remove dots from column names

One straightforward way is to use gsub to remove the periods from the column names:

> names(mydf)
 [1] "JulDay"       "i.46.j.8.k.1" "i.47.j.8.k.1" "i.48.j.8.k.1" "i.46.j.8.k.2"
 [6] "i.47.j.8.k.2" "i.48.j.8.k.2" "i.46.j.8.k.3" "i.47.j.8.k.3" "i.48.j.8.k.3"
[11] "i.46.j.8.k.4" "i.47.j.8.k.4" "i.48.j.8.k.4"
> names(mydf) <- gsub("\\.", "", names(mydf))
> names(mydf)
 [1] "JulDay"  "i46j8k1" "i47j8k1" "i48j8k1" "i46j8k2" "i47j8k2" "i48j8k2" "i46j8k3"
 [9] "i47j8k3" "i48j8k3" "i46j8k4" "i47j8k4" "i48j8k4"

library(janitor)

mydf %>%
  clean_names()

The clean_names function in janitor package will remove any characters that are not lower-case letters, underscores, or numbers. It may convert the periods to underscores though, so if your goal is to get rid of that character completely the gsub solution will work best.

Tags:

R