My data has the following input variables
value- 20,30,50
var1 - 6.5,4,3.2
var2 - 0.6,1.1,0.9
(number of data points are dynamic with each iteration, it could range from 3 to 6)
structure below:
|value|20|30|50|
|var 1|6.5|4|3.2|
|var 2|0.6|1.1|0.9|
I basically need to create a function that takes these variables as dynamic inputs and perform certain arithmetic operations and give a final result as 1 single value.
The catch here is the arithmetic operations can take only 2 values at one time.
For the case above, below is the sample operation:
grp1_value = (20*6.5)+log(0.6) + (30*4)+log(1.1)
grp1_var1 = exp(20*6.5)+exp(30*4)
grp1_var2 = exp(20*0.6)+exp(30*1.1)
grp2= ( 50*3.2)+log(0.9) + (grp1_value * grp1_var1)+log(grp1_var2)
grp2 value should be my output
If my data has more than 3 entries, i should keep doing the operations taking 2 arguments each time.
Any suggestions on the most effective way to write a R function for this case?