My data is:
Prod Vend Capac Dema Price
p1 v2 2 6 1
p1 v1 3 6 2
p1 v3 3 6 2
p2 v1 1 1 1
p2 v3 2 1 2
p2 v2 5 1 2
p3 v1 5 3 3
p3 v2 3 3 4
p3 v3 1 3 5
And I require something like:
Prod Vend Capac Dema Price Source
p1 v2 2 6 1 2
p1 v1 3 6 2 3
p1 v3 3 6 2 1
p2 v1 1 1 1 1
p2 v3 2 1 2 0
p2 v2 5 1 2 0
p3 v1 5 3 3 3
p3 v2 3 3 4 0
p3 v3 1 3 5 0
i have product, vendor, capacity (of vendor), demand (of product), price (of product from vendor). I am sourcing the products based on least price but vendor capacity is a constraint. That is, the selection of a vendor is done by price it has quoted, Price is sorted for the vendors grouped by products.
I am trying it with for loop and if else conditions, the code is getting messier. Is there a clean way to solve it, probably using plyr?