I need to extract a column from a data.table in the form of a vector. I understand that $ works and [] doesn't. Nevertheless, as.vector() fails on a data.table object of a single dimension.
library(data.table)
dt <- iris
setDT(dt)
oneCol1 <- dt$Sepal.Length[1:100] # produces a vector of 100 elements, fine
oneCol2 <- dt[1:100,1] # produces a DT 100 rows by 1 column. I understand limitation.
v <- as.vector(oneCol2)
is.vector(v) # FALSE
The documentation says as.vector()"attempts to coerce ... x, an R object." Nothing happens, though. v remains a DT object.
Sure, I can can use the first method, but I wonder why as.vector() doesn't work.