What is a factor?

Introduzione a R per la finanza

Lore Dirick

Manager of Data Science Curriculum at Flatiron School

Stocks or bonds?

Investment
stock
bond
bond
stock
Introduzione a R per la finanza

Stocks or bonds?

Investment
stock = 2
bond = 1
bond = 1
stock = 2
Introduzione a R per la finanza

Stocks or bonds?

Investment
stock
bond
bond
stock
Introduzione a R per la finanza

Factor creator

answers <- c("stock", "bond", "bond", "stock")
investment <- factor(answers)
investment
stock bond  bond  stock
Levels: bond stock
class(investment)
"factor"
Introduzione a R per la finanza

Factor creator

as.integer(investment)
2 1 1 2
levels(investment)
"bond"  "stock"
Introduzione a R per la finanza

cut() it up

  • Ranking: 1-50
  • 1 is worst, 50 is best
head(ranking)
36 45 32 10 42  8
buckets <- c(0, 10, 20, 30, 40, 50)
ranking_grouped <- cut(ranking, breaks = buckets)
head(ranking_grouped)
(30,40] (40,50] (30,40] (0,10]  (40,50] (0,10] 
Levels: (0,10] (10,20] (20,30] (30,40] (40,50]
Introduzione a R per la finanza

Let's practice!

Introduzione a R per la finanza

Preparing Video For Download...