Help us understand the problem. What is going on with this article?

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

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%>% を出力できます.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした