如何从R中的文件夹中以csv格式保存所有文件?

如何从R中的文件夹中以csv格式保存所有文件?,r,R,我的文件夹中有1500个.csv文件,但我无法直接读取它们 version 1.3.0 info team Ireland info team England info gender male info season 2006

我的文件夹中有1500个
.csv
文件,但我无法直接读取它们

    version 1.3.0                           
info    team    Ireland                     
info    team    England                     
info    gender  male                        
info    season  2006                        
info    date    6/13/2006                       
info    venue   Civil Service Cricket Club, Stormont                        
info    city    Belfast                     
info    toss_winner England                     
info    toss_decision   bat                     
info    player_of_match ME Trescothick                      
info    umpire  R Dill                      
info    umpire  DB Hair                     
info    match_referee   CH Lloyd                        
info    winner  England                     
info    winner_runs 38                      
ball    1   0.1 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.2 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.3 England ME Trescothick  EC Joyce    DT Johnston 0   4
如果我打开每个文件,手动保存,我就可以在R中读取它

    version 1.3.0                           
info    team    Ireland                     
info    team    England                     
info    gender  male                        
info    season  2006                        
info    date    6/13/2006                       
info    venue   Civil Service Cricket Club, Stormont                        
info    city    Belfast                     
info    toss_winner England                     
info    toss_decision   bat                     
info    player_of_match ME Trescothick                      
info    umpire  R Dill                      
info    umpire  DB Hair                     
info    match_referee   CH Lloyd                        
info    winner  England                     
info    winner_runs 38                      
ball    1   0.1 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.2 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.3 England ME Trescothick  EC Joyce    DT Johnston 0   4
因此,我需要自动打开每个文件并将其保存在所需文件夹中的
.csv
?任何帮助都将不胜感激

fi <- list.files("C:/Users/Desktop/DL/Test", full.names = T)
dat <- lapply(fi, read.csv, row.names = NULL)
    version 1.3.0                           
info    team    Ireland                     
info    team    England                     
info    gender  male                        
info    season  2006                        
info    date    6/13/2006                       
info    venue   Civil Service Cricket Club, Stormont                        
info    city    Belfast                     
info    toss_winner England                     
info    toss_decision   bat                     
info    player_of_match ME Trescothick                      
info    umpire  R Dill                      
info    umpire  DB Hair                     
info    match_referee   CH Lloyd                        
info    winner  England                     
info    winner_runs 38                      
ball    1   0.1 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.2 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.3 England ME Trescothick  EC Joyce    DT Johnston 0   4

我假设您在保存csv之前对其进行了一些操作,因为否则这将是徒劳的,最好只是创建一个脚本来复制文件

    version 1.3.0                           
info    team    Ireland                     
info    team    England                     
info    gender  male                        
info    season  2006                        
info    date    6/13/2006                       
info    venue   Civil Service Cricket Club, Stormont                        
info    city    Belfast                     
info    toss_winner England                     
info    toss_decision   bat                     
info    player_of_match ME Trescothick                      
info    umpire  R Dill                      
info    umpire  DB Hair                     
info    match_referee   CH Lloyd                        
info    winner  England                     
info    winner_runs 38                      
ball    1   0.1 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.2 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.3 England ME Trescothick  EC Joyce    DT Johnston 0   4
您可以通过以下方式将lappy与write.csv一起使用:

    version 1.3.0                           
info    team    Ireland                     
info    team    England                     
info    gender  male                        
info    season  2006                        
info    date    6/13/2006                       
info    venue   Civil Service Cricket Club, Stormont                        
info    city    Belfast                     
info    toss_winner England                     
info    toss_decision   bat                     
info    player_of_match ME Trescothick                      
info    umpire  R Dill                      
info    umpire  DB Hair                     
info    match_referee   CH Lloyd                        
info    winner  England                     
info    winner_runs 38                      
ball    1   0.1 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.2 England ME Trescothick  EC Joyce    DT Johnston 0   0
ball    1   0.3 England ME Trescothick  EC Joyce    DT Johnston 0   4
fi<-list.files("C:/Users/Desktop/DL/Test",full.names=T) 

dat<-lapply(fi, read.csv, row.names = NULL)

lapply(seq_along(dat), function(i) {
    write.csv(dat[i], paste0('address/to/file', i,'.csv'))
  })

fiI在read.table中遇到此错误(file=file,header=header,sep=sep,quote=quote,:列数多于列名尝试使用
dat[i]
而不是
dat[[i]]
在保存之前,我没有做任何事情。当我直接导入文件时,我面临问题,而当打开每个文件并按原样保存时,它工作正常。这就是为什么我需要打开每个文件并用相同的名称保存它。你能读文件吗?你能给我看看dat列表的输出吗?我不能读文件,我得到了b我运行此代码时出现以下错误。请发布文件的示例内容。否则我们将在黑暗中拍摄。版本1.3.0信息爱尔兰队信息英格兰队信息性别男性信息2006赛季信息日期2006年6月13日信息场地公务员板球俱乐部,斯托蒙特信息城贝尔法斯特信息掷球冠军英格兰信息掷球决定球棒信息球员匹配我Trescotchick信息裁判R Dill信息裁判DB头发信息比赛裁判CH Lloyd信息获胜者英格兰信息获胜者跑38球10.1英格拉ND ME TraceCouthEc EC乔伊斯DT庄士敦0 0这是文件CashayPraveN。考虑,例如,在原始问题(不在评论中)发布<代码> DPT(DF)< /代码>的输出。