For questions 1,2, and 4 use 1000 simulations to get your answer.
# method one
females <- rbinom(1000, 10, prob=.5)
sum(colSums(rbind(females > 2, females < 8)) == 2)/1000
## [1] 0.9
# method two
successes <- c()
for(i in 1:1000){
females <- sum(sample(c("M", "F"), 10, replace=T) == "F")
successes[i] <- females > 2 && females < 8
}
sum(successes)/1000
## [1] 0.874
# method one
females <- rbinom(1000, 10, prob = .25)
sum(colSums(rbind(females > 2, females < 8)) == 2) / 1000
## [1] 0.489
# method two
successes <- c()
for(i in 1:1000){
females <- sum(sample(c("M", "F"), 10,
replace = T,
prob = c(.75, .25)) == "F")
successes[i] <- females > 2 && females < 8
}
sum(successes)/1000
## [1] 0.465
.5^4
## [1] 0.0625
nums <- c()
for(i in 1:1000){
nums[i] <- sum(rbinom(68, 4, prob=.5) == 4)
}
mean(nums)
## [1] 4.176
x <- c(234, 874, 239, 598)
into R. Demonstrate 3 ways
that you can extract 874 and 598 from the matrix:x <- c(234, 874, 239, 598)
x[c(2,4)]
## [1] 874 598
x[c(F,T,F,T)]
## [1] 874 598
x[-c(1,3)]
## [1] 874 598
x <- matrix(1:20, 10, 2)
into R. Demonstrate three ways
in which you could extract the values 17, 18, 19 from the matrix.x <- matrix(1:20, 10, 2)
x[7:9, 2]
## [1] 17 18 19
x[c(7,8,9), 2]
## [1] 17 18 19
x[c(F,F,F,F,F,F,T,T,T,F),c(F,T)]
## [1] 17 18 19