1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to R

Exercise

Calculating total winnings (3)

Based on the previous analysis, it looks like you had a mix of good and bad days. This is not what your ego expected, and you wonder if there may be a very tiny chance you have lost money over the week in total?

A function that helps you to answer this question is sum(). It calculates the sum of all elements of a vector. For example, to calculate the total amount of money you have lost/won with poker you do:

total_poker <- sum(poker_vector)

Instructions

100 XP
  • Calculate the total amount of money that you have won/lost with roulette and assign to the variable total_roulette.
  • Now that you have the totals for roulette and poker, you can easily calculate total_week (which is the sum of all gains and losses of the week).
  • Print out total_week.