Is it possible to select a column of a data.table and get back a vector? In base R, the argument drop=TRUE
would do the trick. For example,
library(
With data.frame
, the default is drop = TRUE
and in data.table
, it is the opposite while it is done internally. According to ?data.table
drop - Never used by data.table. Do not use. It needs to be here because data.table inherits from data.frame.
In order to get the same behavior, we can use [[
to extract the column by passing a string
identical(dat[["Species"]], iris[, "Species"])
#[1] TRUE
Or
dat$Species
By using [[
or $
, it extracts as a vector
while also bypass the data.table
overhead
See data.table FAQ #1.1. This comes as a feature since 2006.