Reader small image

You're reading from  Machine Learning with R Quick Start Guide

Product typeBook
Published inMar 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781838644338
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Iván Pastor Sanz
Iván Pastor Sanz
author image
Iván Pastor Sanz

Ivn Pastor Sanz is a lead data scientist and machine learning enthusiast with extensive experience in finance, risk management, and credit risk modeling. Ivn has always endeavored to find solutions to make banking more comprehensible, accessible, and fair. Thus, in his thesis to obtain his PhD in economics, Ivn tried to identify the origins of the 2008 financial crisis and suggest ways to avoid a similar crisis in the future.
Read more about Iván Pastor Sanz

Right arrow

Structuring data

After having acquired our target variable and knowing our dataset, we can now move on to the actual data collection based on our target. Here, we will try acquiring the data of the bank according to different years as described in the Collecting the target variable section.

To do this, we create a new variable extracting only the year when a bank went bankrupt, and then we count the number of banks by year:

failed_banks$year<-as.numeric(format(failed_banks$Closing.Date, "%Y"))

Failed_by_Year<-as.data.frame(table(failed_banks$year))
colnames(Failed_by_Year)<-c("year","Number_of_banks")

print(Failed_by_Year)
## year Number_of_banks
## 1 2000 2
## 2 2001 4
## 3 2002 11
## 4 2003 3
## 5 2004 4
## 6 2007 3
## 7 2008 25
...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Machine Learning with R Quick Start Guide
Published in: Mar 2019Publisher: PacktISBN-13: 9781838644338

Author (1)

author image
Iván Pastor Sanz

Ivn Pastor Sanz is a lead data scientist and machine learning enthusiast with extensive experience in finance, risk management, and credit risk modeling. Ivn has always endeavored to find solutions to make banking more comprehensible, accessible, and fair. Thus, in his thesis to obtain his PhD in economics, Ivn tried to identify the origins of the 2008 financial crisis and suggest ways to avoid a similar crisis in the future.
Read more about Iván Pastor Sanz