Skip to Content
Practical Predictive Analytics
book

Practical Predictive Analytics

by Ralph Winters
June 2017
Beginner to intermediate
576 pages
15h 22m
English
Packt Publishing
Content preview from Practical Predictive Analytics

Transforming some variables to integers

If you run an str() function on the variables in the dataframe, you will see that all of them are of type chr (character). We also saw that in the import file dialog:

str(df) 

We will want some of these variables to be integers, so we can use the cast() function to change some of them. Also, clean up some of the leading and trailing spaces using the trim() function:

df$age <- cast(trim(df$age),'integer') df$perstop <- cast(df$perstop,'integer') df$perobs <- cast(df$perobs,'integer') df$ser_num <- cast(df$ser_num,'integer') df$datestop <- cast(df$datestop,'integer') df$timestop <- cast(df$timestop,'integer') ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Superstream: Analytics Engineering

Data Superstream: Analytics Engineering

Alistair Croll, Anna Filippova, Emilie Schario, Lewis Davies, Jacob Frackson, Benn Stancil, Nick Acosta, Elizabeth Caley
R: Predictive Analysis

R: Predictive Analysis

Tony Fischetti, Eric Mayor, Rui Miguel Forte
Python: Advanced Predictive Analytics

Python: Advanced Predictive Analytics

Ashish Kumar, Joseph Babcock

Publisher Resources

ISBN: 9781785886188Supplemental Content