Extract a column from a data.table as a vector, by position

后端 未结 2 1811
情话喂你
情话喂你 2020-11-28 07:42

How do I extract a column from a data.table as a vector by its position? Below are some code snippets I have tried:

DT<-data.table(x=c(1,2),y=c(3,4),z=c(5         


        
2条回答
  •  忘掉有多难
    2020-11-28 08:19

    DT[,get(names(DT)[colNb])]

    where colNb can be an integer (the desired column number) or a variable containing the column number.

提交回复
热议问题