I tried using two ways to add a column in a data.table, it returned different resuts. But I don't understand why, could you please give me a hint? Way 1:
avg_tvd <- dev_survey4[Grp==0 | Grp==1, .(avgTVD = mean(TVDmASL, na.rm=TRUE)),
by = .(Grp,WELL,APA_Pair_ID)]
Here are the results:
Way 2:
avg_tvd <- dev_survey4[Grp==0 | Grp==1, avgTVD := mean(TVDmASL, na.rm=TRUE),
by = .(Grp,WELL,APA_Pair_ID)]
Here are results:
The results of way 1 are what I want. But why way 2 has different results? There are two differences between them:
- Columns of ways 2 are more than way 1;
- Row of way 2 has Grps besides 0 and 1.