我正在尝试学习如何处理多个文件,我在工作目录中有5个示例csv文件,我正在阅读以下代码:
j = list.files()
d = lapply(j, read.csv, skip=6)
每个文件有27列,我正在尝试为每个文件设置列名,我知道如何为单个文件设置列名,例如:
colnames(data) = c("type","date","v1","v2","v3","v4","v5","v6","v7","v8","v9","v10","v11","v12","v13","v14","v15","v16","v17","v18","v19","v20","v21","v22","v23","v24","total")
我只是想知道如何设置目录中的所有文件?
非常感谢, 阿燕答案 0 :(得分:2)
lapply
将再次有效:
a <- data.frame(x=1:3, y=4:6)
my.list <- list(a,a)
lapply(my.list, function(x) {names(x) <- c('a', 'b') ; return(x)})