I have a bed file containing restriction fragments of the mouse genome. Each fragment has a different length/width, like this:
chr start end width
1 chr1 0 3000534 3000534
2 chr1 3000535 3000799 264
3 chr1 3000800 3001209 409
4 chr1 3001210 3001496 286
5 chr1 3001497 3002121 624
Is it possible to combine shorter fragments ( < 500bp) with adjacent fragments using R (see example below) and if yes how?
chr start end width
1 chr1 0 3000534 3000534
2 chr1 3000535 3001209 673
3 chr1 3001210 3002121 910
Note, I don't want to filter out fragments under a certain length, so sub setting the data is not an option.
I hope my question is not too confusing…