所以我试图弄清楚如何清理导入的数据集,并希望将所有列名替换为有空格的地方,并用下划线'_'替换。
我正在使用R和Rstudio。我以为这很简单,但到目前为止,我只发现了围绕解决方案的工作。有没有一种干净便捷的方法?
代码如下。
# load the tidyverse library
library("tidyverse")
setwd("C:/Users/ibrahim.cetinkaya/OneDrive - NTT/Desktop/data")
##################### Part A #####################
# data files (you need to specify the paths of the CSV files (e.g. relativeor absolute) )
files <- c("data/201808.csv",
"data/201809.csv",
"data/201810.csv",
"data/201811.csv",
"data/201812.csv",
"data/201901.csv",
"data/201902.csv",
"data/201903.csv",
"data/201904.csv",
"data/201905.csv",
"data/201906.csv",
"data/201908.csv"
)
#Concatenate into one data frame.
data <- data.frame()
for (i in 1:length(files)){
temp <- read_csv(files[i], skip = 7)
data <- rbind(data, temp)
}
#View to verify
view(data)
#Change the column names to have no spaces between the words
data <- ????