I have have the following code snippet:
data[match(tmp$key, data$key),][[name]] <- all_tmp[[name]]
It works for migrating values from a variable name
containing the column name matching on key
from a data.table tmp
to a data.table data
.
However, it does so only on the first occurrence of key
, as this is a limitation of the match()
function. The few posts I found on SO that use data.table were quite dated, so I am concerned this is no longer relevant to the latest version of data.table. Other posts did not use data.table.
Importantly, I want to reference the column name using a variable name
as opposed to verbatim.
If it was verbatim column "name" I suppose the following would work:
data[all_tmp, on="key", name:=i.name]
Source: https://stackoverflow.com/a/54568079/1515117
Thanks for the help.