Lesson 1 basic

1.3 function

round(3.1415)
## [1] 3
factorial(5)  # 5! = 5*4*3*2*1
## [1] 120
mean(1:6)    #mean:平均、 関数に渡すデータは関数の引数(argument)と呼ぶ
## [1] 3.5
die <- 1:6
mean(die)
## [1] 3.5
sample(x = 1:4, size = 2)
## [1] 1 2
sample(x = die, size = 1)
## [1] 2
sample(x = die, size = 1)
## [1] 5
sample(x = die, size = 1)
## [1] 6
sample(die, size = 1)  
## [1] 5
# Xの指定は、どの引数にどのデータを割り当てるかを指定していた  
# 順番が決まっているので、省略することが可能  
args(sample)
## function (x, size, replace = FALSE, prob = NULL) 
## NULL
args(round)
## function (x, digits = 0) 
## NULL
round(3.1415, digits = 2)
## [1] 3.14
sample(die, 1)
## [1] 3
sample(size =1, x = die)
## [1] 5