How to replace the “.” in column names generated by read.csv() with a single space when exporting?

前端 未结 4 1810
悲&欢浪女
悲&欢浪女 2020-12-24 13:25

I am using R to do some data pre-processing, and here is the problem that I am faced with: I input the data using read.csv(filename,header=TRUE), and then the s

4条回答
  •  情深已故
    2020-12-24 14:11

    To get spaces back in the names, do this (right before you export - R does let you have spaces in variable names, but it's a pain):

    # A simple regular expression to replace dots with spaces
    # This might have unintended consequences, so be sure to check the results
    names(yourdata) <- gsub(x = names(yourdata),
                            pattern = "\\.",
                            replacement = " ")
    

    To drop the first-column index, just add row.names = FALSE to your write.xlsx(). That's a common argument for functions that write out data in tabular format (write.csv() has it, too).

提交回复
热议问题