Pipe-friendly function to make syntactically valid names out of character vectors.
make_clean_names(data)
a data frame or vector
a data frame or a vector depending on the input data
# Vector
make_clean_names(c("a and b", "a-and-b"))
#> [1] "a.and.b" "a.and.b"
make_clean_names(1:10)
#> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10"
# data frame
df <- data.frame(
`a and b` = 1:4,
`c and d` = 5:8,
check.names = FALSE
)
df
#> a and b c and d
#> 1 1 5
#> 2 2 6
#> 3 3 7
#> 4 4 8
make_clean_names(df)
#> a.and.b c.and.d
#> 1 1 5
#> 2 2 6
#> 3 3 7
#> 4 4 8