I'm working with an imported data set that corresponds to the extract below:
set.seed(1)
dta <- data.frame("This is Column One" = runif(n = 10),
"Another amazing Column name" = runif(n = 10),
"!## This Columns is so special€€€" = runif(n = 10),
check.names = FALSE)
I'm doing some cleaning on this data using dplyr
and I would like to change column names to syntatically correct ones and remove the punctuation as a second step. What I tried so far:
dta_cln <- dta %>%
rename(make.names(names(dta)))
generates an error:
> dta_clean <- dta %>% + rename(make.names(names(dta))) Error: All arguments to rename must be named.
Desired result
What I wan to achieve can be done in base:
names(dta) <- gsub("[[:punct:]]","",make.names(names(dta)))
which would return:
> names(dta) [1] "ThisisColumnOne" "AnotheramazingColumnname" "XThisColumnsissospecial"
I want to achieve the same effect but using dyplr
and %>%
.