LoginSignup
8
10

More than 5 years have passed since last update.

勝手に添削:RでCSVファイルを一行ずつ読み込む #rstatsj

Posted at

こういう話がある。

学習データはサンプリングするからメモリに載せられるけど、 予測対象はメモリに乗らない時に一行ずつ読み込んで処理をさせたい。

それ、foreachiterators でできるよ!

R
library(foreach)
library(iterators)

iter <- iread.table("data.csv", header=FALSE, row.names=NULL, sep=",")
foreach(line.df = iter, .final=invisible) %do% {
  write.table(line.df, stdout(), row.names=F, col.names=F, sep=",")
}

もちろん pforeach でもできる。

R
library(pforeach)
library(iterators)

iter <- iread.table("data.csv", header=FALSE, row.names=NULL, sep=",")
npforeach(line.df = iter, .final=invisible)({
  write.table(line.df, stdout(), row.names=F, col.names=F, sep=",")
})

Enjoy!

関連

8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10