I have a data.table like this:
> dt<-data.table(F=rep(c('a','b','c'),each=2), fix=c(10:15),a=c(1:6), b=c(2:7),c=c(3:8))
> dt
F fix a b c
1: a 10 1 2 3
2: a 11 2 3 4
3: b 12 3 4 5
4: b 13 4 5 6
5: c 14 5 6 7
6: c 15 6 7 8
The column F stores the column to be extract for each row. So for the first 2 records column, the column 'a' will be extract while the column 'b' will be extracted for the 3 and 4 record. The 'fix' will be kept for each record. The ideal output should be like this:
F fix new
1: a 10 1
2: a 11 2
3: b 12 4
4: b 13 5
5: c 14 7
6: c 15 8