if 문

금융을 위한 R 중급

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

if 문

ch2_vid3_slides.003.png

if(condition) {
   code
}
금융을 위한 R 중급

연체: if…

default_chance <- runif(1)

if(default_chance > .5) { print("Take action! Likely to default!") }
"Take action! Likely to default!"
default_chance
0.9484406
default_chance <- runif(1)

if(default_chance > .5) { print("Take action! Likely to default!") } default_chance
0.3954069
금융을 위한 R 중급

if - else

ch2_vid3_slides.015.png

if(condition) {
  code if true
} else {
    code if false 
}
금융을 위한 R 중급

연체: if…else…

default_chance <- .4
if(default_chance > .5) {
  print("Take action! Likely to default!")
} else {
  print("No problems here!")
}
"No problems here!"
금융을 위한 R 중급

if - else if - else

if(condition1) {
  code if condition1 is true
} else if(condition2) {
    code if condition2 is true
} else {
    code if both are false
금융을 위한 R 중급

연체: if...else if...else

default_chance <- .4

if(default_chance > .5) {
  print("Take action! Likely to default!")
} else if(default_chance > .3 & default_chance <= .5) {
  print("Warning! Starting to get risky.")
} else {
  print("No problems here!")
}
"Warning! Starting to get risky."
금융을 위한 R 중급

연습해 봅시다!

금융을 위한 R 중급

Preparing Video For Download...