Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
10
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Organization

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

こういう話がある。

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

それ、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!

関連

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
10
Help us understand the problem. What are the problem?