count number of groups containing consecutive numbers
1
0
Entering edit mode
ALok ▴ 170
@alok-2917
Last seen 10.3 years ago
Hi All i have a object gp = c(1,2,3,4,21,22,23,24,38,39) and i want to count number of groups containing consecutive numbers as ans should be three as group1 (1,2,3,4), group2 (21,22,23,24) and group3 contains (38,39) any suggestions [[alternative HTML version deleted]]
• 790 views
ADD COMMENT
0
Entering edit mode
@michael-lawrence-3846
Last seen 3.0 years ago
United States
With Rle from IRanges: sum(runValue(Rle(diff(gp))) == 1) On Thu, Aug 5, 2010 at 4:24 AM, ALok <foralok@gmail.com> wrote: > Hi All > i have a object > gp = c(1,2,3,4,21,22,23,24,38,39) > > and i want to count number of groups containing consecutive numbers > > as > > ans should be three as group1 (1,2,3,4), group2 (21,22,23,24) and group3 > contains (38,39) > any suggestions > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 788 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6