Being new to R, I'm not sure how to go about solving this problem. Hope you can help.
I have a batch tree like the smaller version below.
ID Batch Input_Bx Input_Wt Imp_In Imp_Out
4 B123/1 A123/1 75.1 0.08 0.06
12 B123/2 A123/1 25.2 0.08 0.04
3 B123/2 A123/2 50.1 0.02 0.04
9 B123/3 A123/2 50.0 0.02 0.05
What I want to do, is for every case where there are several input batches (Input_Bx) (e.g. B123/2), I want to multiple the Input_Wt by Imp_In, sum these products for all of the input batches and divide by the sum of the weights of the input batches. So for this fragment of the data table I would get:
Batch B123/1: (75.1 * 0.08) / (75.1) = 0.08
Batch B123/2: (25.5 * 0.08 + 50.1 * 0.02) / (25.2 + 50.1) = 0.04039841
Batch B123/3: (50.0 * 0.02) / (50.0) = 0.02
And produce a new df like:
Batch Eff_Imp Imp_Out
B123/1 0.08 0.06
B123/2 0.04039841 0.04
B123/3 0.02 0.05
An example would be really helpful.
TIA.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…