更改工作目录中所有文件的列名

时间:2012-03-27 14:00:12

标签: r

我正在尝试学习如何处理多个文件,我在工作目录中有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")

我只是想知道如何设置目录中的所有文件?

非常感谢, 阿燕

1 个答案:

答案 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)})