我需要将一个大文件(14 GB)分成较小的文件。该文件的格式为txt,制表符为“;” 我知道它有 70 列(字符串、双精度)。我想读取 100 万个并将它们保存在不同的文件中,file1,file2 ... fileN。
在@MKR的帮助下
但过程非常慢,我尝试使用 fread,但这是不可能的。
我该如何优化这段代码?
新代码
chunkSize <- 10000
conex <- file(description = db, open = "r")
data <- read.table(conex, nrows = chunkSize, header=T, fill=TRUE, sep =";")
index <- 0
counter <- 0
total <- 0
chunkSize <- 500000
conex <- file(description=db,open="r")
dataChunk <- read.table(conex, nrows=chunkSize, header=T, fill=TRUE,sep=";")
repeat {
dataChunk <- read.table(conex, nrows=chunkSize, header=FALSE, fill = TRUE, sep=";", col.names=db_colnames)
total <- total + sum(dataChunk$total)
counter <- counter + nrow(dataChunk)
write.table(dataChunk, file …Run Code Online (Sandbox Code Playgroud)