When you use write.csv or write.table to save your data in a CSV file, you can set the column names to whatever you like by setting the col.names
argument.
But it is assumed that column names are available. After you read the data and R changed the names, you lost this information. To get around this, you can suppress the conversion to get the column names:
df <- read.csv("mydata.csv", check.names=FALSE) orig.cols <- colnames(df) colnames(df) <- make.names(colnames(df)) [your original code] write.csv(df, col.names=orig.cols)
source share