Convert a data frame to a data.table without copy

后端 未结 1 1559
無奈伤痛
無奈伤痛 2020-12-02 07:52

I have a large data frame (in the order of several GB) that I\'d like to convert to a data.table. Using as.data.table creates a copy of the data fr

相关标签:
1条回答
  • 2020-12-02 08:24

    This is available from v1.9.0+. From NEWS:

    o Following this S.O. post, a function setDT is now implemented that takes a list (named and/or unnamed), data.frame (or data.table) as input and returns the same object as a data.table by reference (without any copy). See ?setDT examples for more.

    This is in accordance with data.table naming convention - all set* functions modifies by reference. := is the only other that also modifies by reference.

    require(data.table) # v1.9.0+
    setDT(data) # converts data which is a data.frame to data.table *by reference*
    

    See history for older (now outdated) answers.

    0 讨论(0)
提交回复
热议问题