Last active
August 29, 2015 14:05
-
-
Save dalmat36/fafcdaa1e82e8f6c321f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # An addition | |
| 5 + 5 | |
| # A subtraction | |
| 5 - 5 | |
| # A multiplication | |
| 3 * 5 | |
| # A division | |
| (5 + 5)/2 | |
| # Exponentiation | |
| 2^5 | |
| # Modulo | |
| 5%%3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Assign the value 42 to x | |
| x = 42 | |
| # Print out the value of the variable x | |
| x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Assign the value 5 to the variable called my_apples | |
| my_apples = 5 | |
| # Print out the value of the variable my_apples | |
| my_apples |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| numeric_vector = c(1,10,49) | |
| character_vector = c("a","b","c") | |
| boolean_vector = c(TRUE, FALSE, TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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