i'm using the make.names() column to create better column names, removing illegal symbols etc. how do I apply the new column names to the dataset?
this produces the vector of new column names:
names(data) %>% make.names() i've tried these approaches to get the new column names to replace the old ones (these don't work the way I want):
names(data) %>% make.names() <- data names(data) %>% make.names() <- names(data) data <- names(data) %>% make.names() 2 Answers
You almost had it:
names(data) <- names(data) %>% make.names() With dplyr, we can do
library(dplyr) data <- data %>% set_names(make.names(names(.))) Or with rename_all
data <- data %>% rename_all(~ make.names(.)) 1