I´m trying the following clever attribution using data.table:
for (s in c('G1', 'G2') {
t[t[ , .I[seq(which.max(get(s)), .N)], by = GROUP]$V1, get(s) := 1]
}
For some reason, it complains issuing an error:
Error in get(s) : object 'G1' not found
But, the explicit form works nicely:
t[t[ , .I[seq(which.max(G1), .N)], by = GROUP]$V1, G1 := 1]
Of course, my real dataset has many columns which names unknown in advance. What am I doing wrong here?
Here a sample dataset:
G1 G2 GROUP
0.081975988 0.281210522 A
0.726230621 0.91873287 A
0.938997082 0.146669516 A
0.10564305 0.219593442 A
0.112977071 0.451366779 A
0.157260728 0.570366021 A
0.586841571 0.742955139 B
0.418178989 0.584326765 B
0.290443749 0.435277405 B
0.682695255 0.138739152 B
0.992847073 0.198544311 B
0.401170904 0.347155973 B
0.591182359 0.219964292 C
0.003935376 0.231136145 C
0.666710774 0.479126371 C
0.791187106 0.153873696 C
0.921437692 0.31429481 C
0.88193519 0.801150898 C