用 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(___)