Skip to content

Instantly share code, notes, and snippets.

@Harshit1694
Created July 11, 2019 11:42
Show Gist options
  • Save Harshit1694/40c9c349ddf47e7fd5e663a228d27ed4 to your computer and use it in GitHub Desktop.
Save Harshit1694/40c9c349ddf47e7fd5e663a228d27ed4 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment