I give an example of what I want to achieve in the simplest possible way, I am stuck with it.
I have two data.frame, one with values and another one with percentages:
table <- structure(list(a = 1:10, b = 11:20, c = 21:30, type = c("g",
"g", "g", "g", "g", "g", "g", "g", "g", "g")), row.names = c(NA,
-10L), class = "data.frame")
growth <- structure(list(type = c("g", "g2"), a = c(1, 1), b = c(1.1, 1.3
), c = c(1.2, 1.1)), class = "data.frame", row.names = c(NA,
-2L))
The first table named table looks like this:
a b c type
1 1 11 21 g
2 2 12 22 g
3 3 13 23 g
4 4 14 24 g
5 5 15 25 g
6 6 16 26 g
7 7 17 27 g
8 8 18 28 g
9 9 19 29 g
10 10 20 30 g
and the second one named growth looks like this:
type a b c
1 g 1 1.1 1.2
2 g2 1 1.3 1.1
What I would like to achieve is for example in the first line on the table object:
the type column gives me the growth g from the table growth, then:
a = 1 * 1, b = (1*1)*1.1 + 11, c = ((1*1)*1.1 + 11)*1.2 + 21
and this for each line of the data frame.
Edit: There are many good answers worth checking out. The marked solution is because it is more readable and flexible.