Trier et sous-ensemble de facteurs

Introduction à R pour la finance

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Ordonner

  • Low < Medium < High

ch4_vid2_slides.004.png

Introduction à R pour la finance

Comment ordonner ?

rank <- c("low", "medium", "low", "medium", "high")

rank_wrong_order <- ordered(rank)

rank_wrong_order
low    medium low    medium high  
Levels: high < low < medium
Introduction à R pour la finance

Comment ordonner ?

rank_order <- factor(rank, ordered = TRUE,
                     levels = c("low", "medium", "high"))
rank_order
low    medium low    medium high  
Levels: low < medium < high
summary(rank_order)
low medium   high 
  2      2      1
Introduction à R pour la finance

Sous-ensembles de facteurs

# Seulement low
rank_order[c(1,3)]
low low
Levels: low < medium < high
summary(rank_order[c(1,3)])
low medium   high 
  2      0      0
Introduction à R pour la finance

Sous-ensembles de facteurs

# Seulement low, retirer les niveaux medium et high
rank_order[c(1,3), drop = TRUE]
low low
Levels: low
summary(rank_order[c(1,3), drop = TRUE])
low 
  2 
Introduction à R pour la finance

Passons à la pratique !

Introduction à R pour la finance

Preparing Video For Download...