- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to find the maximum of each outcome of two throws of a die in R?

To find the maximum of each outcome of two throws of a die, we can follow the below steps −

- Create the outcome of two throws of a die using expand.grid function.
- Finding the maximum of each outcome using pmin function.

## Generating the outcome of two throws of a die

Use expand.grid function to create the outcomes of throwing a die two times as shown below −

M<-expand.grid(rep(list(1:6),2)) M

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

Var1 Var2 1 1 1 2 2 1 3 3 1 4 4 1 5 5 1 6 6 1 7 1 2 8 2 2 9 3 2 10 4 2 11 5 2 12 6 2 13 1 3 14 2 3 15 3 3 16 4 3 17 5 3 18 6 3 19 1 4 20 2 4 21 3 4 22 4 4 23 5 4 24 6 4 25 1 5 26 2 5 27 3 5 28 4 5 29 5 5 30 6 5 31 1 6 32 2 6 33 3 6 34 4 6 35 5 6 36 6 6

## Find the maximum of each outcome of the throws

Use pmax function to find the maximum of each throw of die −

M<-expand.grid(rep(list(1:6),2)) do.call(pmax,M)

### Output

[1] 1 2 3 4 5 6 2 2 3 4 5 6 3 3 3 4 5 6 4 4 4 4 5 6 5 5 5 5 5 6 6 6 6 6 6 6

- Related Articles
- How to generate the outcome of three throws of a die in R?
- How to find the maximum value for each column of a matrix in R?
- How to find the maximum of each row in an R data frame?
- How to find the absolute maximum of each group in R data frame?
- How to find the absolute maximum of each group in data.table object in R?
- How to find the maximum value for each row of all matrices stored in an R list?
- How to find the sum of consecutive values considering two values each time in R?
- How to find the index of the minimum and maximum value of a vector in R?
- How to find the position of maximum of each numerical column if some columns are categorical in R data frame?
- How to find the percentage of zeros in each column of a matrix in R?
- How to find the number of zeros in each column of a matrix in R?
- Fill in the blanks: Sum of the probabilities of each outcome in an experiment is ...........
- In a simultaneous throw of a pair of dice, find the probability of getting even number on each die.
- How to find the union of two vectors in R?
- How to find the number of characters in each row of a string column in R?

Advertisements