R语言学习小记2

getwd()

setwd("F:/原始2013-2020/2013-2020气象要素/china_isd_lite_2020")

path <- "F:/原始2013-2020/2013-2020气象要素/china_isd_lite_2020" ##文件目录

fileNames <- dir(path) ##读取该路径下的文件名

filePath <- sapply(fileNames,function(x){

paste(path,x,sep='/') ##生成读取文件路径

})

data <-lapply(filePath, function(x){

read.csv(x,sep = "",quote ="/" ,header = F) ##读取数据,结果为list

})

outPath <- "F:/原始2013-2020/2013-2020气象要素/sc" ##输出路径

out_fileName <- sapply(names(data),function(x){

paste(x, ".txt", 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.names =F )

}

发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章