I want to regroup my dataframe if the existing group has >4 rows, it is further subdivided till it has
a maximum number of 4 rows.
set.seed(100) dat=data.frame("Group"=rep(seq(1:5),sample(1:5))) dat=dat %>% mutate(Group_length = rep(rle(Group )$lengths, rle(Group )$lengths)) dat
Here, in the above example, Group3 has 5 rows. So, it would be divided into two groups consisting
of first 4 rows as a new group and remaining 1 row as another group
I want to have an output like this (Please ignore Temp value in the expected doutput)
set.seed(100) dat1=data.frame("Group"=c(1,1,2,2,2,3,3,3,3,4,5,5,5,5,6), "Temp"=sample(1:15)) dat1