My data are structured in a list (named L) of length 6, so it contains 6 dataframes. I'm correctly accessing the df i want (named D) with: L[[dfname]]
.
My target is to get the sum of a row identified by a vector from another dataframe (named Dselect) selecting one specific row number of D with Dselect$row
and specific columns (one or more) associated to that row contained in a list (named Lselect) i can access with the id contained in Dselect$idforcolumn
. Here's an example of my objects:
D
01 02 03
1 1 1 1
2 1 2 3
3 0 0 0
4 3 2 1
Dselect
row idforcolumn
1 1 103285
2 2 103346
Lselect
$103285
[1] "01" "02"
$103346
[1] "03"
What could be the solution besides structuring my data in a different way?
I thought about something like summing D[ Dselect$row, Lselect[[Dselect$idforcolumn]] ]
. The objective is to return a correctly associated column (in this case: c(2,3)) i can add back in Dselect
. Thanks.