How to extract a column from data.table as a vector by its position? Below are some snippets of code I tried:
DT<-data.table(x=c(1,2),y=c(3,4),z=c(5,6)) DT
I want to get this output using column position
DT$y
Another way to get this output using a column position
DT[,y] #[1] 3 4 is.vector(DT[,y]) #[1] TRUE
It does not give a vector
DT[,2,with=FALSE] # y #1: 3 #2: 4 is.vector(DT[,2,with=FALSE]) #[1] FALSE
These two do not work:
DT$noquote(names(DT)[2])
And this does not give a vector:
DT[,noquote(names(DT)[2]),with=FALSE]
vector r indexing data.table
Wet Feet Nov 18 '13 at 8:37 2013-11-18 08:37
source share