Calculating total winnings in R | Calculation using vector | Question 3
R Programming Language / Vector in R Language
327Program:
# Poker and roulette winnings from Monday to Friday: poker_vector <- c(140, -50, 20, -120, 240) roulette_vector <- c(-24, -50, 100, -350, 10) days_vector <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") names(poker_vector) <- days_vector names(roulette_vector) <- days_vector # Total winnings with poker total_poker <- sum(poker_vector) # Total winnings with roulette total_roulette <- sum(roulette_vector) # Total winnings overall total_week <- total_poker + total_roulette # Print out total_week total_week
Output:
> # Poker and roulette winnings from Monday to Friday: > poker_vector <- c(140, -50, 20, -120, 240) > roulette_vector <- c(-24, -50, 100, -350, 10) > days_vector <- c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") > names(poker_vector) <- days_vector > names(roulette_vector) <- days_vector > > # Total winnings with poker > total_poker <- sum(poker_vector) > > # Total winnings with roulette > total_roulette <- sum(roulette_vector) > > > # Total winnings overall > total_week <- total_poker + total_roulette > > # Print out total_week > total_week [1] -84
Explanation:
Calculation using vector
This Particular section is dedicated to Programs only. If you want learn more about R Programming Language. Then you can visit below links to get more depth on this subject.
# C Tutorials
# JAVA Tutorials
# HTML Tutorials
# Computer Fundamental
# Data Structure
# DBMS Tutorials
SQL
# C# Language
# R Language
# PHP
# Python
# Vue JS