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...