Skip to content

Instantly share code, notes, and snippets.

@Harshit1694 Harshit1694/prob.R
Created Jul 11, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.