Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rの基礎 4 比較演算子と条件分岐、繰り返し
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
xjorv
January 18, 2021
Education
0
430
Rの基礎 4 比較演算子と条件分岐、繰り返し
Rの基礎4では、比較演算子、論理演算子、条件分岐(if文)、繰り返し文(For文)について説明します。
xjorv
January 18, 2021
Tweet
Share
More Decks by xjorv
See All by xjorv
コンパートメントモデル
xjorv
3
5.9k
コンパートメントモデルをStanで解く
xjorv
0
500
生物学的同等性試験 検出力の計算法
xjorv
0
3.6k
生物学的同等性試験ガイドライン 同等性パラメータの計算方法
xjorv
0
6.5k
粉体特性2
xjorv
0
2.6k
粉体特性1
xjorv
0
2.9k
皮膜5
xjorv
0
2.4k
皮膜4
xjorv
0
2.3k
皮膜3
xjorv
0
2.3k
Other Decks in Education
See All in Education
Measuring your measuring
jonoalderson
2
740
AIで日本はどう進化する? 〜キミが生きる2035年の地図〜
behomazn
0
130
Data Presentation - Lecture 5 - Information Visualisation (4019538FNR)
signer
PRO
0
3k
Data Representation - Lecture 3 - Information Visualisation (4019538FNR)
signer
PRO
1
2.9k
Modelamiento Matematico (Ingresantes UNI 2026)
robintux
0
190
子どものためのプログラミング道場『CoderDojo』〜法人提携例〜 / Partnership with CoderDojo Japan
coderdojojapan
PRO
4
18k
悩める リーダー達に 届けたい書籍|レジリエントマネジメント 書籍イントロダクション-260126
mimoza60
1
400
アジャイルなマインドセットを「取り戻す」新人研修づくり
chinmo
1
150
Pen-based Interaction - Lecture 4 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
2.1k
Chapitre_2_-_Partie_3.pdf
bernhardsvt
0
200
Introduction - Lecture 1 - Information Visualisation (4019538FNR)
signer
PRO
0
5.3k
国際卓越研究大学計画|Science Tokyo(東京科学大学)
sciencetokyo
PRO
0
48k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1370
200k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
410
Building AI with AI
inesmontani
PRO
1
790
The SEO identity crisis: Don't let AI make you average
varn
0
410
Mind Mapping
helmedeiros
PRO
1
120
Raft: Consensus for Rubyists
vanstee
141
7.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
630
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
For a Future-Friendly Web
brad_frost
183
10k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
140
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
150
Transcript
Rの基礎4 比較演算子と条件分岐、繰り返し 2020/8/5 Ver. 1.0
比較演算子 2つの値を比較し、Boolean(論理型)を返すためのもの == は2値が等しいときにTRUEを返す != は2値が異なるときにTRUEを返す
比較演算子2 2つの値の大小を比較する演算子 <= は左辺が右辺以下のときにTRUEを返す >= は左辺が右辺以上のときにTRUEを返す < は左辺が右辺未満のときにTRUEを返す > は右辺が左辺未満のときにTRUEを返す
比較演算子3 データの欠損 データの欠損を確認する関数群も比較演算子的に使える NAは欠損値 NaNは計算できない値 Infは無限大 NULLは値がない状態 この4つは統計に使えないので、識別して取り除きたい *NULLは値がないので、ベクトルの要素として残らない
データの欠損の識別 専用の関数を用いる is.nullはデータがあるか is.naはデータがNAか is.nanはデータがNaNか is.infiniteはデータがInfか complete.caseはデータか をそれぞれ示す
論理演算子 aかつb、aまたはbのように、複数の比較を結合するもの A & B はAもBも真ならTRUEを返す A | B はAかBが真ならTRUEを返す
&& や || も同じ意味で使える (ベクター演算の挙動が違う)
条件分岐 if文以外はほぼ必要ない if(条件式){ 条件式がTRUEのときの処理 } else { 条件式がFALSEのときの処理 }
If文の特別な形: ifelse文 1行で書くif文のこと ifelse(条件式, TRUEのときの返り値, FALSEのときの返り値) という形で書く *割とよく使う。libraryを理解した後なら、tidyverseで使えるif_elseのほうが使いやすい
繰り返し文 処理を指定回数繰り返す。for文以外はほぼ不要 for( i in 1:繰り返しの回数){ 繰り返したい処理 } *1:5はc(1, 2,
3, 4, 5)と同じ意味 i には繰り返した回数が代入される
まとめ • 数値の比較には比較演算子を用いる • 欠損値、NaN、Infは専用の関数で識別する • 比較演算子は論理演算子で組み合わせることができる • 条件分岐にはif…else文を用いる •
繰り返しにはfor文を用いる