Learn R Programming

ds4psy (version 1.0.0)

coin: Flip a fair coin (with 2 sides "H" and "T") n times.

Description

coin generates a sequence of events that represent the results of flipping a fair coin n times.

Usage

coin(n = 1, events = c("H", "T"))

Arguments

n

Number of coin flips. Default: n = 1.

events

Possible outcomes (as a vector). Default: events = c("H", "T").

Details

By default, the 2 possible events for each flip are "H" (for "heads") and "T" (for "tails").

See Also

Other sampling functions: dice_2(), dice(), sample_char(), sample_date(), sample_time()

Examples

Run this code
# Basics: 
coin()
table(coin(n = 100))
table(coin(n = 100, events = LETTERS[1:3]))

# Note an oddity:
coin(10, events = 8:9)  # works as expected, but 
coin(10, events = 9:9)  # odd: see sample() for an explanation.

# Limits:
coin(2:3)
coin(NA)
coin(0)
coin(1/2)
coin(3, events = "X")
coin(3, events = NA)
coin(NULL, NULL)

Run the code above in your browser using DataLab