I have the following data.frame.
df = data.frame(a.dfs.56=c(rep("a",8), rep("b",5), rep("c",7), rep("d",10)),
b.fqh.28=rnorm(30, 6, 2),
c.34.2.fgs=rnorm(30, 12, 3.5),
d.tre.19.frn=rnorm(30, 8, 3)
)
How can I substitute all periods "." in the column names to have them become dashes "-"?
I am aware of options like check.names=FALSE
when using read.table
or data.frame
, but in this case, I cannot use this.
I have also tried variations of the following posts, but they did not work for me.
Specifying column names in a data.frame changes spaces to "."
How can I use gsub in multiple specific column in r
R gsub column names in all data frames within a list
Thank you.