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
xjorv
PRO
April 22, 2021
Education
0
36
Rの基礎2_変数と関数.pdf
xjorv
PRO
April 22, 2021
Tweet
Share
More Decks by xjorv
See All by xjorv
コンパートメントモデル
xjorv
PRO
0
4.5k
コンパートメントモデルをStanで解く
xjorv
PRO
0
320
生物学的同等性試験 検出力の計算法
xjorv
PRO
0
2.9k
生物学的同等性試験ガイドライン 同等性パラメータの計算方法
xjorv
PRO
0
4.6k
粉体特性2
xjorv
PRO
0
2.1k
粉体特性1
xjorv
PRO
0
2.4k
皮膜5
xjorv
PRO
0
2k
皮膜4
xjorv
PRO
0
1.9k
皮膜3
xjorv
PRO
0
1.9k
Other Decks in Education
See All in Education
Qualtricsで相互作用実験する「SMARTRIQS」実践編
kscscr
0
220
困ったときのガイドライン / We Support You in Any Situation
yasulab
2
3.7k
Case Studies and Course Review - Lecture 12 - Information Visualisation (4019538FNR)
signer
PRO
1
1.5k
Gemini in Android Studio 使ってますか?
satoryo56
0
290
本の虫になろう
kenjiro56
0
110
HCL Domino 14.0 AutoUpdate を試してみた
harunakano
0
560
Pen-based Interaction - Lecture 4 - Next Generation User Interfaces (4018166FNR)
signer
PRO
0
1.4k
CompTIA Security+ SY0-601 Resumo
malwarilia
2
2.3k
Цифровые финансы - магистерская программа Финэка МГИМО 2024 г.
niellony
0
680
大学業務における生成AI活用の現在地 -基本編-
gmoriki
3
3.2k
エンジニアの イネーブルメントを支える 技術発信文化の作り方
sedo
0
150
技術を楽しもう/enjoy_engineering
studio_graph
1
310
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
326
21k
In The Pink: A Labor of Love
frogandcode
139
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
157
15k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
227
52k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
The Illustrated Children's Guide to Kubernetes
chrisshort
47
48k
Embracing the Ebb and Flow
colly
83
4.4k
Art, The Web, and Tiny UX
lynnandtonic
294
20k
Why You Should Never Use an ORM
jnunemaker
PRO
53
8.9k
Faster Mobile Websites
deanohume
304
30k
Build The Right Thing And Hit Your Dates
maggiecrowley
30
2.3k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
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(返り値)で指定する