R读取许多文件,stringsAsFactors不起作用

时间:2018-06-18 10:26:19

标签: r

我将许多csv / tsv文件导入R. 首先,我定义一个包含所有文件的列表

temp <- list.files(pattern="*\\.tsv$")      # \\ und $ sichern, dass nur die tsv files gewählt werden
temp

这是一个进度条:

pb <- progress_bar$new(format = " progress [:bar] :percent eta: :eta",
                   total = length(temp), clear = FALSE, width= 60)

然后我导入数据(几列)并获得一个list-object:

test_data <- lapply(temp,function(x){
pb$tick()     # progress bar
read.csv(file = x,
       sep ="\t",
       fill = TRUE,
       quote='', 
       header = FALSE,
       stringsAsFactors = FALSE
)[ ,c(287, 288, 289, 290, 291, 292, 293, 304, 370, 661, 662, 812, 813,994, 995, 1002)]
}
) 

然后我将列表组合到data.frame

data_1 <- do.call("rbind", test_data)

我收到以下警告: Warnmeldungen: 1:在[<-.factor*tmp*,ri,value = c(3407L,4546L,4773L,4773L,:   ungültigesFaktorniveau,NA erzeugt 2:在[<-.factor*tmp*,ri,value = c(3407L,4546L,4773L,4773L,:   ungültigesFaktorniveau,NA erzeugt

为什么?

当我插入

stringsAsFactors = FALSE

到导入查询,我收到一个错误:

test_data <- lapply(temp,function(x){
pb$tick()     # progress bar
read.csv(file = x,
       sep ="\t",
       fill = TRUE,
       quote='', 
       header = FALSE,
       stringsAsFactors = FALSE
  )[ ,c(287, 288, 289, 290, 291, 292, 293, 304, 370, 661, 662, 812,     813,994, 995, 1002)]
}
)

Fehler(错误):!self $ finished ist nicht(ist not)TRUE

为什么?

这是文件: https://syzygydeutschland-my.sharepoint.com/:u:/g/personal/florian_roeming_syzygy_de/EdRleruksltMgcvlx18gxSABK15hMZ_swr0GnGMBhXRScw?e=ZJK0UX

0 个答案:

没有答案