data.table Creating a data.table Coerce a data.frame


To copy a data.frame as a data.table, use or data.table:

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

DT <-
# or
DT <- data.table(DF)

This is rarely necessary. One exception is when using built-in datasets like mtcars, which must be copied since they cannot be modified in-place.