7
10

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.

Rのパイプ演算子(%>%) --- 初心者向け ---

Last updated at Posted at 2020-02-14
tags: rBasicLearning

パイプ演算子(%>%)

1. パイプ演算子とは

パイプ演算子の役割は, パイプ演算子の左にあるデータを
右の関数の第一引数に渡すというもの.

1-1. 前準備

パイプ演算子は, Rに元々入っているものではなくdplyrに入っているもの.
library()を用いてインストールしなくてはならない.
今回は, tidyverseで行う.

#install.packages("tidyverse")
library(tidyverse)

1-2. 具体例

data <- c(1, 3, 5, 10, 11, 15) #自分の使いたいデータを入れてください
data %>% head(3)
data %>% mean()
> data %>% head(3)
[1] 1 3 5
> data %>% mean()
[1] 7.5

以下のように, 複数個繋げることもできる

data %>% head(3) %>% mean()
> data %>% head(3) %>% mean()
[1] 3

参考 ショートカット

MACは Control + Shift + m%>% を出力できます.

Windowsは Ctrl + Shift + m%>% を出力できます.

7
10
2

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
7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?