R言語による医療データ分析

R言語によるデータ分析のオンラインコースを中心に、さまざまなデータ分析について記載してあります。

087 filterで行の絞り込み

まとめ一覧

filterで行の絞り込み

  • filterの説明です。
test <- tibble(umare = c(1990, 1992, 1997, 1991),
               height = c(180.0, 176.2, 165.5, 172.3),
               weight = c(70.2, 80.3,65.3,61.1))

test

test$umare > 1995
  • このBooleanをfilterはtibbleの列に適応して、TRUEであるものを抜き出します。
test

test %>% filter(umare > 1995)
test %>% filter(height >= 175)

#実際にdiamondsにfilterを適応してみましょう
diamonds %>% filter(color == "E")

diamonds %>% filter(clarity=="SI1"|clarity=="SI2")
diamonds %>% filter(str_detect(clarity,"^SI\\d+$"))

diamonds$clarity %>% summary()
diamonds %>% filter(str_detect(clarity,"\\d"))

diamonds %>% filter(clarity != "IF")

どうでしょうか?

まとめ一覧