Split a data.table into a list by row number

Scott Prevost

2019/02/28

Split a data.table into a list by row. Each row element then becomes an element in the list.

dt <- dt[, row_id := .I]

listy <- split(dt,
               dt$row_id)

or this may be simpler as it eliminates the requirement to create an additional column holding the row numbers.


listy <- split(dt, seq(nrow(dt)))