diff --git a/R/merge_windows.R b/R/merge_windows.R index 38b6427..64928dd 100644 --- a/R/merge_windows.R +++ b/R/merge_windows.R @@ -4,16 +4,20 @@ merge_windows = function(windows){ chr=as.character(windows[1,1]) start=windows[1,2] end=windows[1,3] - for(i in 2:nrow(windows)){ - if(as.character(windows[i,1]) == chr & windows[i,2] <= end & windows[i,2] >= start){ - end=windows[i,3] - } - else{ - output=rbind(output, c(chr,start, end)) - chr=as.character(windows[i,1]) - start=windows[i,2] - end=windows[i,3] + if(nrow(windows) > 2){ + for(i in 2:nrow(windows)){ + if(as.character(windows[i,1]) == chr & windows[i,2] <= end & windows[i,2] >= start){ + end=windows[i,3] + } + else{ + output=rbind(output, c(chr,start, end)) + chr=as.character(windows[i,1]) + start=windows[i,2] + end=windows[i,3] + } } + return(data.frame(output)) + } else{ + return(windows) } - return(data.frame(output)) -} \ No newline at end of file +}