I'm trying to calculate IRR by group using the package "jrvFinance" - function "irr" but i don't know how.
I have this for only 1 group:
example:
pr1 <- data.frame(idC=1,period = 0:12,
cf = c(-10000,1623.8,1630.47,1637.88,1646.09,1655.21,1665.32,1676.54,1688.99,1702.81,1718.14,1735.15,1753.97))
irr1 <- pr1 %>%
select(cf) %>% .[[1]] %>% irr()
pr1<-pr1 %>%mutate(calculate=irr1)
But i have a data.frame with several groups (idC), how can i get the same result by group in the same data.frame? in this example i only use 2 groups (idC column)
pr1 <- data.frame(idC=1,period = 0:12,
cf = c(-10000,1623.8,1630.47,1637.88,1646.09,1655.21,1665.32,1676.54,1688.99,1702.81,1718.14,1735.15,1753.97))
pr2<-data.frame(idC=2,period = 0:12,
cf = c(-10000,1555.79,1562.19,1569.22,1576.93,1585.40,1594.7,1604.91,1616.12,1628.43,1641.94,1656.79,1673.02))
full_pr=rbind(pr1,pr2)
result I need for full_pr:
idC | period | cf | calculate |
---|---|---|---|
1 | 0 | -10000 | 0.1263736 |
1 | 1 | 1623.8 | 0.1263736 |
1 | 2 | 1630.47 | 0.1263736 |
1 | 3 | 1637.88 | 0.1263736 |
1 | 4 | 1646.09 | 0.1263736 |
1 | 5 | 1655.21 | 0.1263736 |
1 | 6 | 1665.32 | 0.1263736 |
1 | 7 | 1676.54 | 0.1263736 |
1 | 8 | 1688.99 | 0.1263736 |
1 | 9 | 1702.81 | 0.1263736 |
1 | 10 | 1718.14 | 0.1263736 |
1 | 11 | 1735.15 | 0.1263736 |
1 | 12 | 1753.97 | 0.1263736 |
2 | 0 | -10000 | 0.1170392 |
2 | 1 | 1555.79 | 0.1170392 |
2 | 2 | 1562.19 | 0.1170392 |
2 | 3 | 1569.22 | 0.1170392 |
2 | 4 | 1576.93 | 0.1170392 |
2 | 5 | 1585.4 | 0.1170392 |
2 | 6 | 1594.7 | 0.1170392 |
2 | 7 | 1604.91 | 0.1170392 |
2 | 8 | 1616.12 | 0.1170392 |
2 | 9 | 1628.43 | 0.1170392 |
2 | 10 | 1641.94 | 0.1170392 |
2 | 11 | 1656.79 | 0.1170392 |
2 | 12 | 1673.02 | 0.1170392 |