Here’s a brief answer using aggregate….
runs <- cumsum( c(0, diff(my.data$V2) > 1) )
aggregate(V2 ~ runs + V1, my.data, range)[,-1]
V1 V2.1 V2.2
1 1 2 5
2 1 7 11
3 1 13 13
4 2 4 9
5 2 11 13
6 3 1 6
7 3 101 105
More Related Contents:
- How to sum a variable by group
- Aggregate / summarize multiple variables per group (e.g. sum, mean)
- Collapse / concatenate / aggregate a column to a single comma separated string within each group
- Mean per group in a data.frame [duplicate]
- Count number of rows within each group
- Faster ways to calculate frequencies and cast from long to wide
- Count number of rows per group and add result to original data frame
- Apply several summary functions on several variables by group in one call
- Extract row corresponding to minimum value of a variable by group
- Summarizing multiple columns with dplyr? [duplicate]
- Extract the maximum value within each group in a dataframe [duplicate]
- Group by multiple columns and sum other multiple columns
- Select the first and last row by group in a data frame
- Select the top N values by group
- Apply function conditionally
- Summarizing by subgroup percentage in R
- Collapsing rows where some are all NA, others are disjoint with some NAs
- Aggregate a data frame based on unordered pairs of columns
- Aggregate and reshape from long to wide
- Get the means of sub groups of means in R
- Apply several summary functions (sum, mean, etc.) on several variables by group in one call
- Aggregate data in R
- aggregate() puts multiple output columns in a matrix instead
- R sum a variable by two groups [duplicate]
- data.frame Group By column [duplicate]
- R use ddply or aggregate
- Combining duplicated rows in R and adding new column containing IDs of duplicates
- Run a custom function on a data frame in R, by group
- Aggregate by week in R
- How can I count the number of NAs per group?