# What's the next step if I want to know how much I win in lottery in R

I first write

``````A <-replicate(
200,
sample(x=1:49,size=6,replace=FALSE)
)
``````

View(A)

and it comes out a chart

then if three number in each group are the same with (33, 41,59,02,20,71),I get1000\$
if four number ,I get 10000\$
if five number ,I get 100000\$
if six number,I get 1000000\$
and I want to know how much I win when I check 200 lottery
so how can I write it to reach my goal?
thank you for giving me opinion!!!

here is one way

``````set.seed(999)

B<- A <-replicate(
200,
sample(x=1:49,size=6,replace=FALSE)
)

winvector <- c(33, 41,59,02,20,71)

payout <- function(x){
ifelse(x>=3,10^x,0)
}

B[,] <- purrr::map_lgl(A,~ . %in% winvector)

scorevec <- colSums(B) %>% setNames(1:ncol(A))

table(scorevec)
payoutvec <- payout(scorevec)

table(payoutvec)
(sum(payoutvec))``````
2 Likes

may I ask that why it comes out this?
Thank you very much!!!

Oh, you will need dplyr package (or magrittr) for the pipe function %>%

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.