R自带管道符

# compare with dplyr

library(dplyr)
iris %>%
    mutate(p_ratio = Petal.Length / Petal.Width) %>%
    filter(Sepal.Width > 3.5) %>%
    select(Sepal.Length, p_ratio, Sepal.Width) %>%
    slice_head(n = 10)


iris |>
  transform(p_ratio = Petal.Length / Petal.Width) |>
  subset(Sepal.Width > 3.5) |>
  subset(, c(Sepal.Length, p_ratio, Sepal.Width)) |>
  head(10)
posted @ 2022-03-23 20:48  HANBUSHI  阅读(48)  评论(0)    收藏  举报