0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[メモ]summarise(across())を使ったsummarise_each()の代替表現の例

Last updated at Posted at 2020-06-19

データフレームの中で特定の列に限定して、ある処理を行いたいとします。
その場合はdplyrsummarise_each関数が便利です。

たとえば

(データフレーム) %>% summarise_each(mean, matches("(正規表現)", ignore.case=FALSE))

とすれば正規表現を満たす列にのみmean関数が適用されます。

しかしこのようなsummarise_each関数ですが、いずれ非推奨となるようです。

なのでsummarise(across())を使って代替表現を書いてみます。

(データフレーム) %>% summarise(across(matches("(正規表現)", ignore.case=FALSE), mean))

これら出力結果をall_equal関数で比較するとTRUEが返ってくるので、無事代替表現を実装できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?