Skip to content

Instantly share code, notes, and snippets.

@dalmat36
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save dalmat36/fafcdaa1e82e8f6c321f to your computer and use it in GitHub Desktop.

Select an option

Save dalmat36/fafcdaa1e82e8f6c321f to your computer and use it in GitHub Desktop.
# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5)/2
# Exponentiation
2^5
# Modulo
5%%3
# Assign the value 42 to x
x = 42
# Print out the value of the variable x
x
# Assign the value 5 to the variable called my_apples
my_apples = 5
# Print out the value of the variable my_apples
my_apples
# Assign a value to the variables called my_apples and my_oranges
my_apples = 5
my_oranges = 6
# Add these two variables together and print the result
my_apples + my_oranges
# Create the variable my_fruit
my_fruit = my_apples + my_oranges
# Assign a value to the variable called my_apples
my_apples = 5
# Print out the value of my_apples
my_apples
# Add a character
my_oranges = 6
my_oranges
# New variable that contains total amount of fruit
my_fruit = my_apples + my_oranges
my_fruit
# What's the answer to the universe
my_numeric = 42
# The quotation marks indicate that the variable is of type character
my_character = "forty-two"
my_logical = FALSE
# Declare variables of different types
my_numeric = 42
my_character = "forty-two"
my_logical = FALSE
# Check which type these variables have:
class(my_numeric)
class(my_character)
class(my_logical)
numeric_vector = c(1,10,49)
character_vector = c("a","b","c")
boolean_vector = c(TRUE, FALSE, TRUE)
# Poker winnings from Monday to Friday
poker_vector = c(140,-50,20,-120,240)
# Roulette winnings form Monday to Friday
roulette_vector = c(-24,-50,100,-350,10)
#Naming a Vector
# Poker winnings from Monday to Friday
poker_vector = c(140, -50, 20, -120, 240)
# Roulette winnings form Monday to Friday
roulette_vector = c(-24, -50, 100, -350, 10)
names(poker_vector) = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
names(roulette_vector) = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
#Naming a Vector Using a variable
# Poker winnings from Monday to Friday
poker_vector = c(140,-50,20,-120,240)
# Roulette winnings form Monday to Friday
roulette_vector = c(-24,-50,100,-350,10)
# Create the variable days_vector containing "Monday","Tuesday","Wednesday","Thursday","Friday"
days_vector = c("Monday","Tuesday","Wednesday","Thursday","Friday")
#Assign the names of the day to the roulette and poker_vectors
names(poker_vector) = days_vector
names(roulette_vector) = days_vector
#Calculating total Winnings
A_vector = c(1,2,3)
B_vector = c(4,5,6)
# Take the sum of A_vector and B_vector
total_vector = A_vector + B_vector
#Calculating Winnings 2
# Poker winnings from Monday to Friday:
poker_vector = c(140,-50,20,-120,240)
# Roulette winnings form Monday to Friday:
roulette_vector = c(-24,-50,100,-350,10)
# Name poker and roulette
days_vector = c("Monday","Tuesday","Wednesday","Thursday","Friday")
names(roulette_vector) = days_vector
names(poker_vector) = days_vector
# Up to you now:
total_daily = poker_vector + roulette_vector
# Poker winnings from Monday to Friday
poker_vector = c(140,-50,20,-120,240)
# Roulette winnings form Monday to Friday
roulette_vector = c(-24,-50,100,-350,10)
# Name poker and roulette
days_vector = c("Monday","Tuesday","Wednesday","Thursday","Friday")
names(roulette_vector) = days_vector
names(poker_vector) = days_vector
total_poker = sum(poker_vector)
# Up to you now: assign the correct values to:
total_roulette = sum(roulette_vector)
total_week = total_poker + total_roulette
#Comparison total Winnings
# Poker winnings from Monday to Friday
poker_vector = c(140,-50,20,-120,240)
# Roulette winnings form Monday to Friday
roulette_vector = c(-24,-50,100,-350,10)
# Name poker and roulette
days_vector = c("Monday","Tuesday","Wednesday","Thursday","Friday")
names(roulette_vector) = days_vector
names(poker_vector) = days_vector
# Calculate total gains for poker and roulette
total_poker = sum(poker_vector)
total_roulette = sum(roulette_vector)
# Check if you realized higher total gains in poker then in roulette
answer = total_poker > total_roulette
answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment