I have a data.table with 55993 rows and 2923 columns, a subset looks like this:
Name Description GTEX-N7MS-0007-SM-2D7W1 GTEX-N7MS-0008-SM-4E3JI GTEX-N7MS-0011-R10A-SM-2HMJK
ENSG00000223972 DDX11L1 0 0 0
ENSG00000227232 WASH7P 158 166 209
ENSG00000243485 MIR1302-11 0 0 4
ENSG00000237613 FAM138A 0 0 0
ENSG00000268020 OR4G4P 0 0 0
ENSG00000240361 OR4G11P 0 0 0
The Name column is unique so it can be used as the key:
setkey(dat,Name)
I have a list of 175 columns which I want to extract, for e.g. like this:
col.list <- c('GTEX-N7MS-0011-R10A-SM-2HMJK','GTEX-N7MS-0008-SM-4E3JI','GTEX-N7MS-0826-SM-2AXU2')
However, it is possible that the table does contain all the columns.
How do I extract all the rows from data.table, with all the existing columns which match those in col.list? I was thinking something on the lines of:
dat[,.(col.list)]
but it doesn't work.