franknarf1 / r-tutorial

This book covers the essentials of using R
Creative Commons Zero v1.0 Universal
13 stars 4 forks source link

file reading and management #36

Open franknarf1 opened 5 years ago

franknarf1 commented 5 years ago

Reading files

franknarf1 commented 5 years ago

Maybe also cover reading files in other formats (json, matrix)... though maybe that's broad enough for a separate set of notes.

dracodoc commented 4 years ago

Thanks for the great tutorial. I consider myself an advanced data.table user but still learned some new stuff.

Two suggestions on the fread part:

?fread Compressed files with extension .gz and .bz2 are supported if the R.utils package is installed.

DT = fileDT[, rbindlist(setNames(contents, id), idcol="file_id")]

can be

fileDT[, fread(fn), by = .(year, id)]

and the result will be all table combined together with year, id column.