狠狠撸

狠狠撸Share a Scribd company logo
R言語超初心者
1. 基本概念
大阪大学理学部数学科 実験数学 3
担当: 鈴木譲
2015年4月13日
この章の内容
1. クラスとオブジェクト
2. クラス numeric
3. クラス logical
4. クラス character
5. オブジェクトの代入
6. クラスの変換
7. 数値関数
クラスとオブジェクト
上記3クラスに入るオブジェクトの取り扱いを学ぶ
クラス 性質 要素 (オブジェクト)
Numeric 数値 1, -3, 13.2, 7.2e-10, -0.667
logical 論理値 TRUE, FALSE, NA
character 文字列 “interesting”, “How are you?”, “-1.28”
クラス: 同じ性質をもった値の集合
オブジェクト: そのクラスの要素
クラス numeric
1+2 3
1-2 -1
2*3 6
4/5 0.8
2^3 8
(1+2*3)/5^2 0.28
is.numeric (1+2*3)/5^2) TRUE
sqrt(-3) NaN
class(NaN) numeric
pi 3.141593
sin(pi/6) 0.5
tan(pi/4) 1
クラス logical
1==2 FALSE
1<=2 TRUE
1>=2 FALSE
1!=2 TRUE
1>2 FALSE
1<2 TRUE
1==2||1>2 FALSE
1>2&&1<2 FALSE
is.logical(1>2) TRUE
Is.logical (NA) TRUE NAは、値が欠損していることを意味する
クラス character
”Thank“ “Thank”
is.character(“Thank") TRUE
paste("Thank","you") “Thank you”
past0(“Mon”,”day”) “Monday”
substring("Thank", 2,4) “han”
regexpr(“day”, “Tuesday”) 5
Characterクラスを入力とする関数
オブジェクトの代入
x<-2
x
x+3
x
x<-x+4.15
x
y<- -1.28
x+y
Xに2を代入
(初期値)
yに-1.28を代入
(初期値)
Xにx+4.15(=6.15)を代入
(更新)
何かを代入するまでは、
xはただの記号。
何らかのクラスの値をもって
そのクラスのオブジェクトになる
クラスの変換
z<-as.numeric(2<1)
z
is.logical(z)
is.numeric(z)
as.numeric(TRUE) 1となる
as.numeric(FALSE) 0となる
as.numeric(NA) NAはNAになる
as.numeric(“17”) numericの17になる
as.logical(0) 0はFALSEで他はTRUEになる
as.logical(-5)
logical クラスを
numeric クラスに変換
数値関数
関数 意味 X=1.570 (=pi/2) X=-- 0.523 (=-pi/6)
sqrt(x) 平方根 1.253314 NaN
abs(x) 絶対値 1.570796 1.047
exp(x) 指数 4.810477 0.592
log(x) 対数 0.4515827 NaN
sin(x) 正弦 0 -0.5
cos(x) 余弦 0.5 0.8660254
tan(x) 正接 Inf -0.5773503
floor(x) (絶対値の)切上げ 1 -1
trunc(x) 切下げ 1 0
round(x) 四捨五入 2 -1

More Related Content

Viewers also liked (8)

ガイダンス
ガイダンスガイダンス
ガイダンス
Joe Suzuki
?
相互情报量を用いた独立性の検定
相互情报量を用いた独立性の検定相互情报量を用いた独立性の検定
相互情报量を用いた独立性の検定
Joe Suzuki
?
MaCaulay2 Miuraパッケージの開発と今後
MaCaulay2 Miuraパッケージの開発と今後MaCaulay2 Miuraパッケージの開発と今後
MaCaulay2 Miuraパッケージの開発と今後
Joe Suzuki
?
OMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
OMNI-Prop: Seamless Node Classification on Arbitrary Label CorrelationOMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
OMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
Yuto Yamaguchi
?
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Yuto Yamaguchi
?
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Taiji Suzuki
?
関西狈滨笔厂+読み会発表スライド
関西狈滨笔厂+読み会発表スライド関西狈滨笔厂+読み会発表スライド
関西狈滨笔厂+読み会発表スライド
Yuchi Matsuoka
?
相互情报量を用いた独立性の検定
相互情报量を用いた独立性の検定相互情报量を用いた独立性の検定
相互情报量を用いた独立性の検定
Joe Suzuki
?
MaCaulay2 Miuraパッケージの開発と今後
MaCaulay2 Miuraパッケージの開発と今後MaCaulay2 Miuraパッケージの開発と今後
MaCaulay2 Miuraパッケージの開発と今後
Joe Suzuki
?
OMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
OMNI-Prop: Seamless Node Classification on Arbitrary Label CorrelationOMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
OMNI-Prop: Seamless Node Classification on Arbitrary Label Correlation
Yuto Yamaguchi
?
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Online User Location Inference Exploiting Spatiotemporal Correlations in Soci...
Yuto Yamaguchi
?
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Minimax optimal alternating minimization \\ for kernel nonparametric tensor l...
Taiji Suzuki
?
関西狈滨笔厂+読み会発表スライド
関西狈滨笔厂+読み会発表スライド関西狈滨笔厂+読み会発表スライド
関西狈滨笔厂+読み会発表スライド
Yuchi Matsuoka
?

More from Joe Suzuki (20)

搁と笔测迟丑辞苍を比较する
搁と笔测迟丑辞苍を比较する搁と笔测迟丑辞苍を比较する
搁と笔测迟丑辞苍を比较する
Joe Suzuki
?
搁集会蔼统数研
搁集会蔼统数研搁集会蔼统数研
搁集会蔼统数研
Joe Suzuki
?
E-learning Development of Statistics and in Duex: Practical Approaches and Th...
E-learning Development of Statistics and in Duex: Practical Approaches and Th...E-learning Development of Statistics and in Duex: Practical Approaches and Th...
E-learning Development of Statistics and in Duex: Practical Approaches and Th...
Joe Suzuki
?
分枝限定法でモデル选択の计算量を低减する
分枝限定法でモデル选択の计算量を低减する分枝限定法でモデル选択の计算量を低减する
分枝限定法でモデル选択の计算量を低减する
Joe Suzuki
?
连続変量を含む条件付相互情报量の推定
连続変量を含む条件付相互情报量の推定连続変量を含む条件付相互情报量の推定
连続変量を含む条件付相互情报量の推定
Joe Suzuki
?
E-learning Design and Development for Data Science in Osaka University
E-learning Design and Development for Data Science in Osaka UniversityE-learning Design and Development for Data Science in Osaka University
E-learning Design and Development for Data Science in Osaka University
Joe Suzuki
?
UAI 2017
UAI 2017UAI 2017
UAI 2017
Joe Suzuki
?
AMBN2017 サテライトワークショップ
AMBN2017 サテライトワークショップAMBN2017 サテライトワークショップ
AMBN2017 サテライトワークショップ
Joe Suzuki
?
CRAN Rパッケージ BNSLの概要
CRAN Rパッケージ BNSLの概要CRAN Rパッケージ BNSLの概要
CRAN Rパッケージ BNSLの概要
Joe Suzuki
?
Forest Learning from Data
Forest Learning from DataForest Learning from Data
Forest Learning from Data
Joe Suzuki
?
A Bayesian Approach to Data Compression
A Bayesian Approach to Data CompressionA Bayesian Approach to Data Compression
A Bayesian Approach to Data Compression
Joe Suzuki
?
A Conjecture on Strongly Consistent Learning
A Conjecture on Strongly Consistent LearningA Conjecture on Strongly Consistent Learning
A Conjecture on Strongly Consistent Learning
Joe Suzuki
?
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
Joe Suzuki
?
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
Joe Suzuki
?
研究绍介(学生向け)
研究绍介(学生向け)研究绍介(学生向け)
研究绍介(学生向け)
Joe Suzuki
?
Bayesian Criteria based on Universal Measures
Bayesian Criteria based on Universal MeasuresBayesian Criteria based on Universal Measures
Bayesian Criteria based on Universal Measures
Joe Suzuki
?
MDL/Bayesian Criteria based on Universal Coding/Measure
MDL/Bayesian Criteria based on Universal Coding/MeasureMDL/Bayesian Criteria based on Universal Coding/Measure
MDL/Bayesian Criteria based on Universal Coding/Measure
Joe Suzuki
?
The Universal Measure for General Sources and its Application to MDL/Bayesian...
The Universal Measure for General Sources and its Application to MDL/Bayesian...The Universal Measure for General Sources and its Application to MDL/Bayesian...
The Universal Measure for General Sources and its Application to MDL/Bayesian...
Joe Suzuki
?
Universal Prediction without assuming either Discrete or Continuous
Universal Prediction without assuming either Discrete or ContinuousUniversal Prediction without assuming either Discrete or Continuous
Universal Prediction without assuming either Discrete or Continuous
Joe Suzuki
?
Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Bayesian network structure estimation based on the Bayesian/MDL criteria when...Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Joe Suzuki
?
搁と笔测迟丑辞苍を比较する
搁と笔测迟丑辞苍を比较する搁と笔测迟丑辞苍を比较する
搁と笔测迟丑辞苍を比较する
Joe Suzuki
?
搁集会蔼统数研
搁集会蔼统数研搁集会蔼统数研
搁集会蔼统数研
Joe Suzuki
?
E-learning Development of Statistics and in Duex: Practical Approaches and Th...
E-learning Development of Statistics and in Duex: Practical Approaches and Th...E-learning Development of Statistics and in Duex: Practical Approaches and Th...
E-learning Development of Statistics and in Duex: Practical Approaches and Th...
Joe Suzuki
?
分枝限定法でモデル选択の计算量を低减する
分枝限定法でモデル选択の计算量を低减する分枝限定法でモデル选択の计算量を低减する
分枝限定法でモデル选択の计算量を低减する
Joe Suzuki
?
连続変量を含む条件付相互情报量の推定
连続変量を含む条件付相互情报量の推定连続変量を含む条件付相互情报量の推定
连続変量を含む条件付相互情报量の推定
Joe Suzuki
?
E-learning Design and Development for Data Science in Osaka University
E-learning Design and Development for Data Science in Osaka UniversityE-learning Design and Development for Data Science in Osaka University
E-learning Design and Development for Data Science in Osaka University
Joe Suzuki
?
AMBN2017 サテライトワークショップ
AMBN2017 サテライトワークショップAMBN2017 サテライトワークショップ
AMBN2017 サテライトワークショップ
Joe Suzuki
?
CRAN Rパッケージ BNSLの概要
CRAN Rパッケージ BNSLの概要CRAN Rパッケージ BNSLの概要
CRAN Rパッケージ BNSLの概要
Joe Suzuki
?
Forest Learning from Data
Forest Learning from DataForest Learning from Data
Forest Learning from Data
Joe Suzuki
?
A Bayesian Approach to Data Compression
A Bayesian Approach to Data CompressionA Bayesian Approach to Data Compression
A Bayesian Approach to Data Compression
Joe Suzuki
?
A Conjecture on Strongly Consistent Learning
A Conjecture on Strongly Consistent LearningA Conjecture on Strongly Consistent Learning
A Conjecture on Strongly Consistent Learning
Joe Suzuki
?
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
A Generalization of the Chow-Liu Algorithm and its Applications to Artificial...
Joe Suzuki
?
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
A Generalization of Nonparametric Estimation and On-Line Prediction for Stati...
Joe Suzuki
?
研究绍介(学生向け)
研究绍介(学生向け)研究绍介(学生向け)
研究绍介(学生向け)
Joe Suzuki
?
Bayesian Criteria based on Universal Measures
Bayesian Criteria based on Universal MeasuresBayesian Criteria based on Universal Measures
Bayesian Criteria based on Universal Measures
Joe Suzuki
?
MDL/Bayesian Criteria based on Universal Coding/Measure
MDL/Bayesian Criteria based on Universal Coding/MeasureMDL/Bayesian Criteria based on Universal Coding/Measure
MDL/Bayesian Criteria based on Universal Coding/Measure
Joe Suzuki
?
The Universal Measure for General Sources and its Application to MDL/Bayesian...
The Universal Measure for General Sources and its Application to MDL/Bayesian...The Universal Measure for General Sources and its Application to MDL/Bayesian...
The Universal Measure for General Sources and its Application to MDL/Bayesian...
Joe Suzuki
?
Universal Prediction without assuming either Discrete or Continuous
Universal Prediction without assuming either Discrete or ContinuousUniversal Prediction without assuming either Discrete or Continuous
Universal Prediction without assuming either Discrete or Continuous
Joe Suzuki
?
Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Bayesian network structure estimation based on the Bayesian/MDL criteria when...Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Bayesian network structure estimation based on the Bayesian/MDL criteria when...
Joe Suzuki
?

基本概念