data.table Creating a data.table Modify a data.frame with setDT()


For efficiency, data.table offers a way of altering a data.frame or list to make a data.table in-place:

# example data.frame
DF = data.frame(x = letters[1:5], y = 1:5, z = (1:5) > 3)

# modification

Note that we do not <- assign the result, since the object DF has been modified in-place.

The class attributes of the data.frame will be retained:

sapply(DF, class)
#         x         y         z 
#  "factor" "integer" "logical"