Skip to content

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 example 3^2 is 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 %% 3 is 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%%4

Variable 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
x

Variable 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_apples

Variable 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_fruit

Apples 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을 μ–»μ—ˆμŠ΅λ‹ˆλ‹€.

β€Œ
β€Œ
β€Œ