我想对数据帧df进行分组/分组
a <- c(1,2,3,4,5,6,7,8,9,10)
b <- c(10,20,30,40,50,60,70,80,90,100)
c <- c("a","a","b","b","b","a","a","b","c","c")
df <- data.frame(x_value=a, y_value=b, speed=c)
输入以在“速度”列上分隔数据帧,如下所示
x_value y_value speed
1 1 10 a
2 2 20 a
****
3 3 30 b
4 4 40 b
5 5 50 b
****
6 6 60 a
7 7 70 a
****
8 8 80 b
****
9 9 90 c
10 10 100 c
所以我最终以df [1],包含第1行和第2行,df [2],包含第3、4和5行,等等。
答案 0 :(得分:2)
我们需要NotFoundError: Expect status [200] from Google Storage. But got status 404.
Path: '/darianhickman-201423.appspot.com/logo.jpg'.
Request headers: None.
Response headers: {'date': 'Sun, 30 Dec 2018 18:54:54 GMT', 'connection': 'close', 'server': 'Development/2.0'}.
Body: ''.
Extra info: None.
和split
来创建rleid
个list
data.frame
要提取数据帧,请使用library(data.table)
lst1 <- split(df, rleid(df$speed))
[[
或从lst1[[1]]
lst1[[2]]
base R
或使用grp <- cumsum(c(TRUE, df$speed[-1] != df$speed[-nrow(df)]))
rle