You need to use sequence
and rle
:
> sequence(rle(as.character(dataset$input))$lengths)
[1] 1 1 2 1 2 1 1 2 3 4 1 1
More Related Contents:
- Create counter of consecutive runs of a certain value
- Count number of rows per group and add result to original data frame
- Counting the number of elements with the values of x in a vector
- Add count of unique / distinct values by group to the original data
- Is there a dplyr equivalent to data.table::rleid?
- Include levels of zero count in result of table()
- Fixing the order of facets in ggplot
- Create grouping variable for consecutive sequences and split vector
- Count number of occurences for each unique value
- Create a group number for each consecutive sequence
- generate sequence within group in R [duplicate]
- Create group names for consecutive values
- rep() with each equals a vector
- Count non-NA values by group [duplicate]
- Count number of rows by group using dplyr
- Generate an incrementally increasing sequence like 112123123412345
- How to count the frequency of a string for each row in R
- Extend contigency table with proportions (percentages)
- Find the n most common values in a vector [duplicate]
- Cumulative count of each value [duplicate]
- Find start and end positions/indices of runs/consecutive values
- Insert blanks into a vector for, e.g., minor tick labels in R
- Use rle to group by runs when using dplyr
- Find the most frequent value by row
- Tidyr how to spread into count of occurrence [duplicate]
- Count number of columns by a condition (>) for each row
- Count unique values for every column
- Deleting every n-th row in a dataframe
- How can I count the number of NAs per group?
- Create a Vector of All Days Between Two Dates