Skip to content

Instantly share code, notes, and snippets.

@kdmgs110
Last active August 5, 2017 09:21
Show Gist options
  • Save kdmgs110/6c1f8a9b523a5b9a57fbc11b65aec4ec to your computer and use it in GitHub Desktop.
Save kdmgs110/6c1f8a9b523a5b9a57fbc11b65aec4ec to your computer and use it in GitHub Desktop.
大数法則1
#[1] 10回分試行する場合
n = 10
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
sample(roll, n, replace=T) #sample関数(後述)
table(sample(roll, n, replace=T)) #サイコロの目を、100回振ったものをtableで表示
barplot(table(sample(roll, n, replace=T))) #それを棒グラフで表示
#[2] 100回試行する場合
n = 100
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
sample(roll, n, replace=T) #sample関数(後述)
table(sample(roll, n, replace=T)) #サイコロの目を、100回振ったものをtableで表示
barplot(table(sample(roll, n, replace=T))) #それを棒グラフで表示
#[3] 1000回試行する場合
n = 1000
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
sample(roll, n, replace=T) #sample関数(後述)
table(sample(roll, n, replace=T)) #サイコロの目を、100回振ったものをtableで表示
barplot(table(sample(roll, n, replace=T))) #それを棒グラフで表示
#[4] 10000回試行する場合
n = 10000
roll <- c("1","2","3","4","5","6") #サイコロの目を指定
sample(roll, n, replace=T) #sample関数(後述)
table(sample(roll, n, replace=T)) #サイコロの目を、100回振ったものをtableで表示
barplot(table(sample(roll, n, replace=T))) #それを棒グラフで表示
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment