I am having difficulty with writing a script in R.
What I am trying to get is:
- I have a list of Product Codes and Product Descriptions. What I am trying to get is the view in table 2 with MinPercentile >=0.95, MinPercentile >=0.80 and MinPercentile >=0.60 columns filled in. The rule for MinPercentile >=0.95 is:
if the value in the Percentile column is greater or equals to 0.95, and this value is the closest to 0.95 at the same time (so if there were two values say 0.98 and 0.99 then I would be interested in 0.98 since it is closer to 0.95) then bring in the invoice price appearing for that value for tat prodcode to column MinPercentile >=0.95. So looking at the table one 4.19 is the invoice price for the percentile 0.956 which is the closest to 0.95.
The same rule applies to other two columns though only the value criteria are different, we are looking at >= 0.80 and >= 0.60 and again need to bring the invoice price for the closest to 0.60 and 0.80 percentile values into my MinPercentile >=0.80 and MinPercentile >=0.60 columns.
Ideally I am looking to create Table 2 at the product code level that is a summary of table 1, meeting described by me criteria. I hope it makes sense. I would really appreciate help with that.
Appreciate your effort.