My data has 3 columns (id, time, conc). I am looking for a concise way to add the column (using Chain.jl and DataFramesMeta.jl) as described in the title. Example code is below:
df = DataFrame(id = sort(repeat([1, 2, 3], 10)),
time = repeat(0:10:90, 3),
conc = rand(30))
@chain df begin
@aside concs_20 = @chain _ begin
@rsubset :time == 20
@select :id :conc_20hr = :conc
end
leftjoin(_, concs_20, on=[:id])
end
For example, in R, I can do the task concisely (using the library data.table) as follows:
The last example matches what OP has written in data.table. I would just make a small substitution of first to only as it is safer (you are sure there is only one match for :time .== 20)