I have data on groups of bonds and their cash flows. Each IssueID contains multiple BondIDs. Each BondID has its own cash flow, rendered as a list within the data frame via dplyr mutate. The cash flow lists do not have equal numbers of elements. The data structure is:
| IssueID | BondID | cashflow |
|---|---|---|
| AA | AA1 | c(-1000, 50, 50, 1050) |
| AA | AA2 | c(-1000, 25, 25, 25, 25, 1025) |
| AB | AB1 | c(-2000, 100, 100, 2100) |
| AB | AB1 | c(-1000, 75, 75, 75, 75, 1075) |
I need to sum each BondID's cashflows by IssueID while maintaining each element's position in the list. The output needs to look like:
| IssueID | sumcashflow |
|---|---|
| AA | c(-2000, 75, 75, 1075, 25, 1025) |
| AB | c(-3000, 175, 175, 2175, 75, 1075) |
Appreciate any assistance. Thanks.
Am not able to sum the lists.