Minimal example:
dt <- data.table(a=c(1,2,3),b=c(4,5,6))
That looks like that:
> dt
a b
1: 1 4
2: 2 5
3: 3 6
Suppose I want to index the column where there is a 6 value, in this toy example it's easy since we know the column:
> dt[,.(b)]
b
1: 4
2: 5
3: 6
Now what if this dt had several thousand columns and we wouldn't know where the 6 lies.
I tried this:
> dt[,.SD==6]
a b
[1,] FALSE FALSE
[2,] FALSE FALSE
[3,] FALSE TRUE
and this:
> dt[,lapply(.SD,`==`,6)]
a b
1: FALSE FALSE
2: FALSE FALSE
3: FALSE TRUE
and also that:
> dt[,lapply(.SD,function(x) any(x==6))]
a b
1: FALSE TRUE
But i can't get the original column back:
b
1: 4
2: 5
3: 6
