Groups Name start end sum
1 G1 A 451 954 1405
2 G1 B 451 951 1402
3 G1 C 451 969 1420
4 G1 D 463 870 1333
5 G1 E 463 888 1351
6 G1 X 230 450 680
7 G1 Z 229 450 681
8 G2 F 119 841 960
9 G2 G 118 842 960
10 G3 H 460 790 1250
11 G3 I 123 300 177
12 G4 J 343 878 1221
13 G4 K 343 878 1221
14 G4 L 320 862 1182
And I would like for each Groups to keep only one interval representant (an interval meaning that df$start and df$end overlaps between rows, I explain:
For exemple in the G1 there are 2 intervals groups :
Interval 1 (with min = 451 and max = 969):
Name start end sum
A 451 954 1405
B 451 951 1402
C 451 969 1420
D 463 870 1333
E 463 888 1351
Then I tak the bigest df$sum (here 1420)
and
Interval2 (with min = 229 and max = 450)
Name start end sum
X 230 450 680
Z 229 450 681
Then I tak the bigest df$sum (here 681)
If I do that for the all df I get :
Groups Name start end sum
3 G1 C 451 969 1420
7 G1 Z 229 450 681
9 G2 G 118 842 960
10 G3 H 460 790 1250
11 G3 I 123 300 177
12 G4 J 343 878 1221
Does someone have an idea ? Here are the data :
structure(list(Groups = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 3L, 3L, 4L, 4L, 4L), .Label = c("G1", "G2", "G3", "G4"
), class = "factor"), Name = structure(c(1L, 2L, 3L, 4L, 5L,
13L, 14L, 6L, 7L, 8L, 9L, 10L, 11L, 12L), .Label = c("A", "B",
"C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "X", "Z"), class = "factor"),
start = c(451L, 451L, 451L, 463L, 463L, 230L, 229L, 119L,
118L, 460L, 123L, 343L, 343L, 320L), end = c(954L, 951L,
969L, 870L, 888L, 450L, 450L, 841L, 842L, 790L, 300L, 878L,
878L, 862L), sum = c(1405L, 1402L, 1420L, 1333L, 1351L, 680L,
681L, 960L, 960L, 1250L, 177L, 1221L, 1221L, 1182L)), class = "data.frame", row.names = c(NA,
-14L))