批量读取文件无法正确读取

时间:2021-03-27 08:08:42

标签: r file

我有 30 个 .txt 文件需要读取到小标题。其面板数据一共108M

问题是有些文件在所有值都存在的情况下被正确读取,但有些文件在值存在时读取为 NA!此外,文件包括很多空行....

这是我使用的:

read_clean_table<-function(x){
    x<-read.table(x, header = TRUE, fill = TRUE)
    x[-(1:4),] #first 4 rows are system data
  }

filenames<-list.files(path="./ML", pattern = ".*.txt", full.names=TRUE)

#read files and merge to table, first rows removed, FileName is the name of file
files<-filenames%>%
  set_names(.) %>%
  map_df(read_clean_table, .id = "FileName")%>%
  mutate(FileName=str_replace_all(basename(FileName), pattern="\\.txt",""))

我也尝试过 read.delim 并取得了同样的成功...

这就是问题的样子

enter image description here

已编辑:

添加了两个文件

https://drive.google.com/drive/folders/1gDss6qV9aFUMpJFGHPMQZbTITJ9av-py?usp=sharing

0 个答案:

没有答案
相关问题