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の基礎2_変数と関数.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
xjorv
April 22, 2021
Education
69
0
Share
Rの基礎2_変数と関数.pdf
xjorv
April 22, 2021
More Decks by xjorv
See All by xjorv
コンパートメントモデル
xjorv
3
5.9k
コンパートメントモデルをStanで解く
xjorv
0
510
生物学的同等性試験 検出力の計算法
xjorv
0
3.7k
生物学的同等性試験ガイドライン 同等性パラメータの計算方法
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
勝手にCULTIBASE で広げよう、探究の輪! - CULTIVAL 2026
hiroc_sk
1
150
Virtual and Augmented Reality - Lecture 8 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
2.1k
From Participation to Outcomes
territorium
PRO
0
440
Pen-based Interaction - Lecture 4 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
2.2k
View Manipulation and Reduction - Lecture 9 - Information Visualisation (4019538FNR)
signer
PRO
1
2.6k
Tips for the Presentation - Lecture 2 - Advanced Topics in Big Data (4023256FNR)
signer
PRO
0
550
AI時代において英語学習は本当に必要? ~未経験からのバイリンガルキャリアの始め方を教えます~
kekekenta
0
130
2026年度春学期 統計学 講義の進め方と成績評価について (2026. 4. 9)
akiraasano
PRO
0
130
Google AI Studio 開発者向け完全ガイド プロトタイピ まで ングからReactアプリ 構築・マルチモーダル活用
mickey_kubo
1
130
GitHubによるWebアプリケーションのデプロイ / 07-github-deploy
kaityo256
PRO
1
250
Data Presentation - Lecture 5 - Information Visualisation (4019538FNR)
signer
PRO
1
3.1k
Visualisation Techniques - Lecture 8 - Information Visualisation (4019538FNR)
signer
PRO
1
2.9k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
890
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
140
The Limits of Empathy - UXLibs8
cassininazir
1
300
エンジニアに許された特別な時間の終わり
watany
106
240k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
510
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
680
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
64
53k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
100
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
270
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
210
Transcript
Rの基礎 2 変数と関数 2020/8/5 Ver. 1.0
変数と関数とは? 変数 関数 数字や文字を入れておく箱 数字を入れると、別のものを吐き出す箱 “犬” Dog 変数 “犬” 関数
c(5, 10, 15) mean 10 代入 引数 返り値 *Rではmeanは平均値を計算する関数
変数の作り方 • 変数名は英数字のみで、先頭の文字には数字を使えない • 変数には<-を使って代入する • 変数名を入力すると、代入したものが呼び出される Xに1を代入 Xを呼び出し 変数は電卓のメモリー機能(M+など)と同じようなもの
変数の扱い方 • 変数は演算に利用できる • 変数には型がある Xに1を代入すると、 • X + 10は11になり、演算できる
• Xの型はNumericになる Yに“dog”を代入すると、 • Yの型はCharacterになる 1. class(◦◦)で◦◦の型を知ることができる 2. 変数の型は代入されたものによって勝手に決まる(型推論)
変数の型と演算 • 型が違うと計算できず、エラーがでる • 型をclass関数でチェックし、間違いを探す 1 + “dog” は型が演算の形にあっていないので、計算できない
関数 • 関数とは、引数を演算し、返り値を返すもの • Rには多数の関数が登録されている(組み込み関数) ひきすう mean()は平均値、sd()は標準偏差、summary()はデータの要 約を計算するための関数、xが引数となる。
引数と返り値 • 引数は、関数の後のカッコの中に入れる変数のこと • 返り値は、関数で生成するもの xがmean関数の引数、3.5が返り値となる
関数を作る 自分で関数を作ることもできる • 関数も変数のように代入して作る • 関数はfunction(引数){処理}という形で書く • 返り値はreturn(返り値)で指定する *返り値はreturn関数を使わず、返り値を書くだけでも決定される
まとめ • 変数は数字・文字列を保存しておくための箱 • 関数は引数を処理して返り値を返すもの • 関数はfunction(引数){処理}で記述できる • 関数の返り値はreturn(返り値)で指定する