I'm new to R and I'm doing a practice question.
Simulate rolling a fair coin 200 times, then plot a histogram of the data.
I did:
outcomes <- c("heads", "tails")
sim_fair_coin <- sample(outcomes, size = 200, replace = TRUE)
hist(table(sim_fair_coin))
You can use the ggplot2
package as well.
x <- as.data.frame(sim_fair_coin)
ggplot(x, aes(factor(sim_fair_coin))) + geom_bar(width=.5)