# 11.1: Basic Probability Calculations

- Page ID
- 8780

Let’s create a vector of outcomes from one to 6, using the `seq()`

function to create such a sequence:

```
outcomes <- seq(1, 6)
outcomes
```

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

Now let’s create a vector of logical values based on whether the outcome in each position is equal to 1. Remember that `==`

tests for equality of each element in a vector:

```
outcome1isTrue <- outcomes == 1
outcome1isTrue
```

`## [1] TRUE FALSE FALSE FALSE FALSE FALSE`

Rememer that the simple probability of an outcome is number of occurrences of the outcome divided by the total number of events. To compute a probability, we can take advantage of the fact that TRUE/FALSE are equivalent to 1/0 in R. The formula for the mean (sum of values divided by the number of values) is thus exactly the same as the formula for the simple probability! So, we can compute the probability of the event by simply taking the mean of the logical vector.

```
p1isTrue <- mean(outcome1isTrue)
p1isTrue
```

`## [1] 0.17`