I have the following data:
library(tidyverse)
df <- tribble(~SwapID, ~SwapLegID, ~LegPayerID, ~ CurrencyID, ~NotionalAmount,
'AB-D-0001', 1, 'AB', 'CAD', 250000000,
'AB-D-0001', 2, 'BMO', 'CAD', 250000000,
'AB-D-0002', 1, 'AB', 'CAD', 250000000,
'AB-D-0002', 2, 'RBC', 'CAD', 250000000,
'AB-D-0004', 1, 'AB', 'CAD', 250000000,
'AB-D-0004', 2, 'TD', 'USD', 250000000,
'AB-D-0005', 1, 'BMO', 'USD', 416666668,
'AB-D-0005', 2, 'AB', 'CAD', 548750002)
I need to find a way to divide "NotionalAmount" with each other for each respective "SwapID" and "SwapLegID".
Therefore, for "SwapID" AB-D-0005, I want to divide 548750002 by 416666668 to get 1.317 and assign this data element a new column.
FXrateSwap<-SwapLegs%>%
arrange(SwapID,SwapLegID)%>%
select(SwapID,SwapLegID,LegPayerID,CurrencyID,NotionalAmount)