I too think I worded it incorrectly... so the second two columns of the matrix are the start and end of an interval however, because some of the intervals overlap, I want to limit the number of intervals I have to deal with.
So therefore, (5 10) should merge with (7 18) making (5 18) and then (5 18) should merge with (16 20) giving (5 20) whereas (1 4) has no overlap with any other interval and is therefore left on its own Ideal output would just be a collapsing of the matrix sample start end # 5 20 # 1 4 I got this to work using unique(c(5:10,7:18,16:20,1:4)) which gives me a c(1:4,5:20) However, I have to do this on a very large dataset and the numbers are more like c(100542:100782,598322:598821,...) any help would be appreciated thanks -- View this message in context: http://r.789695.n4.nabble.com/merge-function-in-R-tp2324684p2324855.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.