用到R语言自带的mtcars数据集,首先我们把它转化成tibble形式,然后存放在mtcars1中。准备代码如下:
library(tidyverse)
mtcars %>% as_tibble() -> mtcars
mtcars %>% group_by(cyl) %>% slice(1:3) %>% ungroup()
mtcars %>% group_by(cyl) %>% arrange(desc(hp)) %>% slice(1:3) %>% ungroup()
mtcars %>% group_by(cyl) %>% filter(hp > 150) %>% ungroup()
mtcars %>% group_by(cyl) %>% summarise(hp_max = max(hp)) %>% ungroup()