In this lab, I will take you a trip to the Statisticians paradise where we will learn how to keep track of betting progress and how to do some analyses on past actions. We will also learn some data-analytical skills for uplift performance at the tables and fire off a career as a professional gambler!

Note: R is case sensitive!

The task lists for the lab 2:

1. Create a vector

2. Naming a vector

3. Calculating the vector (Arithmetic)

4. Comparing the vector (logical)

**Steps for the task: Create a vector**

Let’s go ‘Vegas!’ Vegas variable declaration where the value is “GO!”

Step 1: Vectors are one-dimension arrays that generally hold numeric, character or logical data or you can say, a vector is a simple tool to store the data.

In this lab, I will use a

Create a vector with the combination function c() in R, and put the vector elements separately by a comma between the parentheses.

R command for vectors:

numeric_vector <- c(1,2,3) or c(1:3)

charcter_vector <- c(“a”,”b”,”c”)

After creating vectors, we can use them to do calaculations.

Step 2: Declare a boolean_vector that contains the three elements, True, False, and True in this order.

R command: boolean_vector <- c(TRUE, FALSE, TRUE)

Step 3: In this step, we will use our data analytical superpowers on our last week winning and losses games of poker and roulette in Las Vegas.

Firstly, we need to collect all the winnings and losses for the last week

For Poker_vector:

- On Monday, won $140
- Tuesday, lost $ 50
- Wednesday, won $20
- Thursday, lost $120
- Friday, won $240

For roulette_vector:

- Monday, lost $24
- Tuesday, lost $50
- Wednesday, won $100
- Thursday, lost $350
- Friday, won $10

Secondly, We need to create the variables poker_vector and roulette _vector for winning /losses poker and roulette to use those data in R

**Steps for the task: Naming a vector**

As a data analyst, It is very important to understand the behaviour of data that you are using, and what each element refers to.

In the previous task, we created a vector.In this task, We will show Naming a vector. You need to give a name to the elements of the vector with the names() function.

Step1: Vector itself would show which day it belongs. Assign days as names function of poker_vector and roulette_vector

An exercise of names functions: Suppose, You created a vector some_vector, values are ” John Doe”, Poker Player”. Then you declare names () function for the vector element that assigned the first element = Name and second element = Profession.

Step 2: In this steps, we will see how efficient way we can declare the naming function rather than typing and re-typing information again and again.

Firstly, we will assign the days of the week vector to a variable **days_vector** that will contain the days of the week for poker and roulette game.

Secondly, we will use **days_vector **to set the names of poker_vector and roulette vector.

**Steps for the task: Calculating the vector (Arithmetic)**

In this task, we will do some data analytical magic on the poker and roulette. We will calculate the total winnings of the games because it is time to get those Ferraris in our garage, right!

Step 1: Arithmetic calculations on vectors

In this step, we will know how to sum two vectors in R. It does usually the element-wise sum.

For instance, c (1, 2, 3) +c(4, 5, 6)

c(1+4, 2+5, 3+6)

c(5, 7, 9)

or do calculations with variables that represent vectors

a <- c (1, 2, 3)

b <- c(4, 5, 6)

c < – a+b

Step 2: Calculating the total

Firstly, we need to understand what was our profit and loss per day of the week was.

Secondly, the total daily profit is the sum of the profit/loss that we realised on poker and roulette per day.

We can calculate the total winnings in R, just summation of the two vectors

Assign variable, total_daily = The Sum of (poker_vector + roulette_vector), the result will be combination of how much we won or lost on each day in total poker and roulette

Step 3: In the previous step, we had the data a mix of good and bad days.

In this step, we will calculate the totals amount of won/loss for a week for poker and roulette. Because there may be very tiny chance we have lost money over the week in total?

**total_week = sum of all gains and losses of the week**

We will use a function called **sum()** to analysis total week gain and loss together. **Sum()** calculates the sum of all elements of a vector.

Total amount of money we won/lost with poker/roulette

**total_poker <- sum(poker_vector)**

**total roulette <- sum(roulettle_vector)**

Instructions:

- Calculate the total amount of money that we won/lost with roulette and poker
- Calculate the total week for poker and roulette

**Steps for the task: Comparing the vector (logical)**

In this task, we will change our data analysis strategy and we will do the deeper analysis for calculating more winnings.

Step 1: roulettleIn this step, we will compare two games:

Comparision symbols in R : <, >, <=, >=, =

Instructions for comparing,

- Calculate total_poker and total roulette using the sum() function
- Check if total gains in poker are higher than for roulette by using comparison

**Thank you 🙂**