I am working with an imported dataset 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 am doing some cleaning up of this data with dplyr, and I would like to change the column names to parse them and remove the punctuation as a second step. What I have 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 wanted to achieve can be done in the database:
names(dta) <- gsub("[[:punct:]]","",make.names(names(dta)))
which will return:
> names(dta)
[1] "ThisisColumnOne" "AnotheramazingColumnname" "XThisColumnsissospecial"
I want to achieve the same effect, but using dyplrand %>%.
source
share