Home / Programs / Create a vector using R Question 2
🚀 Programming Example

Create a vector using R Question 2

👁 396 Views
💻 Practical Program
📘 Step Learning

After one week in Las Vegas and still zero Ferraris in your garage, you decide that it is time to start using your data analytical superpowers.

Before doing a first analysis, you decide to first collect all the winnings and losses for the last week:

For poker_vector:

  • On Monday you won $140
  • Tuesday you lost $50
  • Wednesday you won $20
  • Thursday you lost $120
  • Friday you won $240

For roulette_vector:

  • On Monday you lost $24
  • Tuesday you lost $50
  • Wednesday you won $100
  • Thursday you lost $350
  • Friday you won $10

You only played poker and roulette, since there was a delegation of mediums that occupied the craps tables. To be able to use this data in R, you decide to create the variables poker_vector and roulette_vector.

💻 Program Code

# Poker winnings from Monday to Friday
poker_vector <- c(140, -50, 20, -120, 240)

# Roulette winnings from Monday to Friday
roulette_vector <-  c(-24, -50, 100, -350, 10)

poker_vector
roulette_vector
                        

🖥 Program Output

> # Poker winnings from Monday to Friday
> poker_vector <- c(140, -50, 20, -120, 240)
> 
> # Roulette winnings from Monday to Friday
> roulette_vector <-  c(-24, -50, 100, -350, 10)
> 
> poker_vector
[1]  140  -50   20 -120  240
> roulette_vector
[1]  -24  -50  100 -350   10
                            

📘 Explanation

Assign the winnings/losses for roulette to the variable roulette_vector.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.