0

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.

lmo
  • 37,904
  • 9
  • 56
  • 69
fedezi
  • 21
  • 4
  • class(D) says it's a dataframe (it returns "data.frame"). dput(D) shows something like (consider the actual D has a column per month): `structure(list('01' = c(0.0787998558083221,..., 0.062248188622537), '02' = c(0.077476783314289,... ...), .Names = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"), class = "data.frame", row.names = c(NA, -13L))` – fedezi Aug 23 '17 at 10:44
  • The data structure reminds me of SQL, maybe you could look into the `sqldf` package to see if there is a convenient solution. Right now, this selection process seems overly complicated. – LAP Aug 23 '17 at 10:57

0 Answers0