Using rleid
from data.table
,
library(data.table)
rleid(x, prefix = "Group_")
#[1] "Group_1" "Group_1" "Group_1" "Group_2" "Group_2" "Group_2" "Group_3" "Group_4" "Group_4" "Group_5" "Group_5"
More Related Contents:
- Is there a dplyr equivalent to data.table::rleid?
- Create counter within consecutive runs of values
- Find start and end positions/indices of runs/consecutive values
- Use rle to group by runs when using dplyr
- Create counter of consecutive runs of a certain value
- How to prevent ifelse() from turning Date objects into numeric objects
- Evaluate expression given as a string
- Select groups based on number of unique / distinct values
- Scheduling R Script
- Create stacked barplot where each stack is scaled to sum to 100%
- Change variable name in for loop using R
- How do you order the fill-colours within ggplot2 geom_bar
- Simplest way to get rbind to ignore column names
- Growing a data.frame in a memory-efficient manner
- Difference between passing options in aes() and outside of it in ggplot2
- Setting document title in Rmarkdown from parameters
- passing several arguments to FUN of lapply (and others *apply)
- ggplot2 multiple scales/legends per aesthetic, revisited [duplicate]
- Apply several summary functions (sum, mean, etc.) on several variables by group in one call
- Order of operator precedence when using “:” (the colon)
- What methods can we use to reshape VERY large data sets?
- Determining UTM zone (to convert) from longitude/latitude
- Using R to download zipped data file, extract, and import .csv
- Layered axes in ggplot?
- How do I close unused connections after read_html in R
- different colors for each bar in stacked bar graph – base graphics
- consolidating data frames in R
- Text-mining with the tm-package – word stemming
- Adding percentage labels on pie chart in R
- show multiple plots from ggplot on one page in r