開始使用免費開始

用 replicate() 做模擬

使用 replicate() 來模擬 100,000 次拋銅板實驗,等待第一次出現正面,且正面的機率為 20%。接著呼叫 qplot() 繪製這次模擬的直方圖。

本練習屬於課程

R 的機率基礎

檢視課程

練習說明

  • 使用 replicate() 來模擬 100,000 次幾何試驗。請將提供給你的運算式複製貼上,作為 replicate() 的第二個引數。
  • replications 呼叫 qplot(),繪製直方圖。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Existing code for finding the first instance of heads
which(rbinom(100, 1, 0.2) == 1)[1]

# Replicate this 100,000 times using replicate()
replications <- 

# Histogram the replications with qplot
qplot(___)
編輯並執行程式碼