Finding groups of contiguous numbers in a list

<>

This question already has an answer here:

Answers


Just use diff:

x = c(2, 3, 4, 4, 5, 12, 13, 14, 15, 16, 17, 17, 20)

start = c(1, which(diff(x) != 1 & diff(x) != 0) + 1)
end = c(start - 1, length(x))

x[start]
# 2 12 20
x[end]
# 5 17 20

Need Your Help

RequiredFieldValidator to prompt ModalPopupExtender

c# asp.net modalpopupextender requiredfieldvalidator

I have a bunch of RequiredFieldValidators on a page and I would like the ErrorMessage="" to display in a ModalPopupExtender rather than on the page. So when they click submit and a textbox isn't fi...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.