Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
6
Help us understand the problem. What is going on with this article?
@Quantas

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

More than 1 year has passed since last update.
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%>% を出力できます.

6
Help us understand the problem. What is going on with this article?
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
Quantas
初心者向けの投稿を多めにしてます!

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
6
Help us understand the problem. What is going on with this article?