JiaxiangBU / tutoring2

The collection of Python and R code scripts to tutor others.
https://jiaxiangbu.github.io/tutoring2/
Other
8 stars 7 forks source link

根据某列连续相同的值分组 #55

Closed slsongge closed 4 years ago

slsongge commented 4 years ago

问题

按照D列分组,D列只有两种唯一值(0、1),把连续的0或者1作为一组,最后生成n个数据框。

代码

library(tidyverse)

set.seed(45L)
df <- tibble(
  A = runif(10, 0, 1),
  B = runif(10, 0, 1),
  D = c(0,0,0,1,1,1,1,0,0,1)
)
JiaxiangBU commented 4 years ago

@slsongge https://github.com/JiaxiangBU/tutoring2/blob/a526ac133671fe61a25784781e70e81baef3a1e4/jinxiaosong/nested.md