O'Reilly logo

Practical Predictive Analytics by Ralph Winters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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') ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required