I have many columns for which i want to calculate value based on function (1 + x) ^ k, where x is a value from a particular column and k is index of column for which we try to calculate. I want to calculate this only for a subset of all the columns of the table.
For axample:
df = data.frame(A = c(0.1, 0.05, 0.2), B = c(1, 1, 1), C = c(NA, NA, NA), D = c(NA, NA, NA)
I want to apply the function only to columns C and D, using values from column A.
For example df[1,4] would be calculated as (1 + (-0.1)^4 because 4 is index of column D.
An alternative interpretation is that for the selected columns (C and D in this example), the value is value from previous column multiplied by (1+x), i.e. df[1,4] = df[1,3] * (1 + (-0.1)), giving the same result