One common problem with the R language is the bulk reading of files and the batch output of the results. Bulk Read
Bulk read data, there are two forms, read all the files in a directory, read multiple tables from the database.
# #读取同一目录下的所有文件
path <-"F:/rfile/od-b/data" # #文件目录
fileNames <-dir (path) # #获取该路径下的文件名
FilePath <-sapply (fileNames, function (x) {
paste (path,x,sep= '/')}) # #生成读取文件路径
data <-lapply ( FilePath, function (x) {
read.csv (x, Header=t)}) # #读取数据, the result is a list
# #从数据库中读取数据类似上面, gets the file name in the database, Write a regular filter file name after the for loop read.
Batch Output
Batch output CSV file for results, where data is list format
Outpath <-"F:/rfile/od-b/consequence" # #输出路径
out_filename <-sapply (names (data), function (x) {
paste (x, ". csv", sep= ')}) # #csv格式
out_filepath <-sapply (out_filename, function (x) {
paste (Outpath, x,sep= '/')}) # #输出路径名
# #输出文件 for
(i in 1:length (data)) {
write.csv (Data[[i]], file=out_filepath[i], row.name=f)
}