当有多个数据集(CSV格式)文件时,用read.csv一个一个读取非常繁琐,有没有批量读取的方法?
示例代码
# setwd("./BB/Venn_13Oct") ## 如果用了project就无需这一步
#filenames
filenames
ldf % lapply(read.csv) ## we use 'lapply' function to read all the files in filenames
names(ldf)
df1
有时我需要合并多个txt文本到一个中去,再用lapply就不好使,可以用for循环,如下:
fil_path_nam
fil_nam
temp
for (file_i in 1:length(fil_path_nam)) {
temp0 % readLines
temp
}
write(temp, file = "./R/all.txt")
some examples下面这个例子是我有6个CSV文件,每个文件中有一列是相同的,想要进一步把这6个文件按照共有的这一列合并到一个数据框中,用merge函数
filenames
# write a function
d_merge_jj
names(file1)[1]
merge.file
# write merged content Job done!
file
write.table(merge.file, file, sep = ",")
print("Job done!")
}
## Implementation
for(i in 1:6){
ao
ao
ao
ao
d_merge_jj (ao,pilot,filenames[i])
}