Reputation: 11
df = data.frame(A = c(1, 1, 2), B = c(1, 600, 600), C = c(0.02, 0.03, 0.01))
For each column (A & B) the union are corresponding an index value for an individual interval. That I need to sum to create vector that I will use to perform financial projection / valuation. In the end, I would like to retrieve the overlaps inclued
1 to 600 - 0.03
2 to 600 - 0.01
### 1 - 0.05
### 2 - 0.04
### 600 - 0.04
Upvotes: 0
Views: 54
Reputation: 50668
You're leaving us guessing somewhat as to what the rules are for reproducing your expected output.
I can't reproduce your output but is this what you're after?
library(dplyr)
library(tidyr)
df %>%
pivot_longer(-C, values_to = "id") %>%
select(-name) %>%
group_by(id) %>%
summarise(value = sum(C))
## A tibble: 3 x 2
# id value
# <dbl> <dbl>
#1 1 0.07
#2 2 0.01
#3 600 0.04
Upvotes: 1