Take Notes
Add notes here about the concepts you've learned and code cells with code you want to keep.
μλ λ°©μ
μ€λ₯Έμͺ½ νΈμ§κΈ°μλ μ°μ΅ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ R μ½λλ₯Ό μ λ ₯ν΄μΌ ν©λλ€. 'λ΅λ³ μ μΆ' λ²νΌμ λλ₯΄λ©΄, κ° μ½λ μ€μ΄ Rμ μν΄ ν΄μλκ³ μ€νλλ©°, μ½λκ° μ¬λ°λ₯Έμ§ μ¬λΆμ λν λ©μμ§λ₯Ό λ°κ² λ©λλ€. R μ½λμ μΆλ ₯μ μ€λ₯Έμͺ½ νλ¨ μ½μμ νμλ©λλ€.
Rμ μ£Όμμ μΆκ°νκΈ° μν΄ # κΈ°νΈλ₯Ό μ¬μ©ν©λλ€. μ΄λ κ² νλ©΄ μ¬λ¬λΆκ³Ό λ€λ₯Έ μ¬λλ€μ΄ R μ½λμ λ΄μ©μ μ΄ν΄ν μ μμ΅λλ€. λ§μΉ νΈμν°μ²λΌ λ§μ΄μ£ ! μ£Όμμ R μ½λλ‘ μ€νλμ§ μμΌλ―λ‘ κ²°κ³Όμ μν₯μ μ£Όμ§ μμ΅λλ€. μλ₯Ό λ€μ΄, μ€λ₯Έμͺ½ νΈμ§κΈ°μμ 3 + 4 κ³μ°μ μ£Όμμ
λλ€.
λν μ½μμμ μ§μ R λͺ λ Ήμ μ€νν μλ μμ΅λλ€. μ΄λ R μ½λλ₯Ό μ€ννλ μ’μ λ°©λ²μ λλ€. μλνλ©΄ μ μΆν λ΄μ©μ΄ μ¬λ°λ₯Έμ§ νμΈλμ§ μκΈ° λλ¬Έμ΄μ£ .
Add your notes here
# Add your code snippets here
# Calculate 3 + 4
3 + 4
# Calculate 6 + 12
6 + 12
Arithmetic with R
In its most basic form, R can be used as a simple calculator. Consider the following arithmetic operators:
- Addition:
+ - Subtraction:
- - Multiplication:
* - Division:
/ - Exponentiation:
^ - Modulo:
%%
The last two might need some explaining:
- The
^operator raises the number to its left to the power of the number to its right: for example3^2is 9. - The modulo returns the remainder of the division of the number to the left by the number on its right, for example 5 modulo 3 or
5 %% 3is 2.
With this knowledge, follow the instructions to complete the exercise.
7%%4# An addition
5 + 5
# A subtraction
5 - 5
# A multiplication
3 * 5
# A division
(5 + 5) / 2
# Exponentiation
3^3
# Modulo
7%%4Variable assignment
A basic concept in (statistical) programming is called a variable.
A variable allows you to store a value (e.g. 4) or an object (e.g. a function description) in R. You can then later use this variable's name to easily access the value or the object that is stored within this variable.
You can assign a value 4 to a variable my_var with the command
my_var <- 4
# Assign the value 42 to x
x <- 56
# Print out the value of the variable x
xVariable assignment (2)
Suppose you have a fruit basket with five apples. As a data analyst in training, you want to store the number of apples in a variable with the name my_apples.
# Assign the value 5 to the variable my_apples
my_apples <- 5
# Print out the value of the variable my_apples
my_applesVariable assignment (3)
Every tasty fruit basket needs oranges, so you decide to add six oranges. As a data analyst, your reflex is to immediately create the variable my_oranges and assign the value 6 to it. Next, you want to calculate how many pieces of fruit you have in total. Since you have given meaningful names to these values, you can now code this in a clear way:
my_apples + my_oranges
# Assign a value to the variables my_apples and my_oranges
my_apples <- 5
# Add these two variables together
my_oranges <- 3
# Create the variable my_fruit
my_fruit <- my_apples + my_oranges
minus_furit <- my_apples - my_oranges
mul_fruit <- my_apples * my_oranges
div_fruit <- my_apples / my_oranges
my_fruit
minus_furit
mul_fruit
div_fruitApples and oranges
Common knowledge tells you not to add apples and oranges. But hey, that is what you just did, no :-)? The my_apples and my_oranges variables both contained a number in the previous exercise. The + operator works with numeric variables in R. If you really tried to add "apples" and "oranges", and assigned a text value to the variable my_oranges (see the editor), you would be trying to assign the addition of a numeric and a character variable to the variable my_fruit. This is not possible.
λ£°λ μ μΉλ¦¬/ν¨λ°°λ₯Ό λ³μ roulette_vectorμ ν λΉνμΈμ. $24λ₯Ό μμ νμ $50μ μμμΌλ©°, $100μ μ»μκ³ , $350μ μμμΌλ©°, $10μ μ»μμ΅λλ€.
β
β