Introduction to R for Finance
Lore Dirick
Manager of Data Science Curriculum at Flatiron School
Investment |
---|
stock |
bond |
bond |
stock |
Investment | |
---|---|
stock | = 2 |
bond | = 1 |
bond | = 1 |
stock | = 2 |
Investment |
---|
stock |
bond |
bond |
stock |
answers <- c("stock", "bond", "bond", "stock")
investment <- factor(answers)
investment
stock bond bond stock
Levels: bond stock
class(investment)
"factor"
as.integer(investment)
2 1 1 2
levels(investment)
"bond" "stock"
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]
Introduction to R for Finance