Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f <- function(toss=1){
- x <- sample(1:2, size=toss, replace=TRUE)
- y <- sample(1:2, size=toss, replace=TRUE)
- return(cbind(x,y))
- }
- set.seed(2500)
- toss_times <- as.data.frame(f(2000))
- library(plyr)
- freq <- ddply(toss_times, ~x, summarize,
- y1=sum(y==1), y2=sum(y==2))
- row.names(freq) <- paste0('x',1:2)
- prob_table1 <- freq_table[,-1]/2000
- prob_table1
- prob_x <- table(toss_times$x)/2000
- prob_y <- table(toss_times$y)/2000
- prob_table2 <- outer(prob_x,prob_y,'*')
- row.names(prob_table2) <- paste0('x',1:2)
- colnames(prob_table2) <- paste0('y',1:2)
- prob_table2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement