Change column types in current H2O frame

Syntax

Convert columns to categorical columns

    _h2oframe _toenum columnlist , {generate(newcolumnlist)|replace}

Convert columns to numeric columns

    _h2oframe _tonumeric columnlist , {generate(newcolumnlist)|replace}

Convert columns to string columns

    _h2oframe _tostring columnlist , {generate(newcolumnlist)|replace}

columnlist is a list of column names in the H2O frame; see Specifying a list of columns for more information.

 _toenum_options                   Description
 ---------------------------------------------------------------------------------
 * generate(newcolumnlist)         generate newcolumn_1, ..., newcolumn_k for each
                                     column in columnlist
 * replace                         replace string columns in columnlist with
                                     numeric columns
 ---------------------------------------------------------------------------------
 * Either generate(newcolumnlist) or replace is required.


 _tonumeric_options                Description
 ---------------------------------------------------------------------------------
 * generate(newcolumnlist)         generate newcolumn_1, ..., newcolumn_k for each
                                     column in columnlist
 * replace                         replace string columns in columnlist with
                                     numeric columns
 ---------------------------------------------------------------------------------
 * Either generate(newcolumnlist) or replace is required.


 _tostring_options                 Description
 ---------------------------------------------------------------------------------
 * generate(newcolumnlist)         generate newcolumn_1, ..., newcolumn_k for each
                                     column in columnlist
 * replace                         replace numeric columns in columnlist with
                                     string columns
 ---------------------------------------------------------------------------------
 * Either generate(newcolumnlist) or replace is required.

Description

_h2oframe _toenum converts columns in columnlist to categorical (enum). Columns in columnlist that are already categorical will not be converted.

_h2oframe _tonumeric converts columns in columnlist to numeric. Columns in columnlist that are already numeric will not be converted.

_h2oframe _tostring converts columns in columnlist to string. Columns in columnlist that are already string will not be converted.

Options for _h2oframe _toenum

Either generate() or replace must be specified.

generate(newcolumnlist) specifies that a new column be created for each column in columnlist. newcolumnlist must contain the same number of new column names as there are columns in columnlist.

replace specifies that the columns in columnlist be converted to categorical columns.

Options for _h2oframe _tonumeric

Either generate() or replace must be specified. With either option, if an observation in a specified string column contains nonnumeric characters, then the observation will contain a missing value.

generate(newcolumnlist) specifies that a new column be created for each column in columnlist. newcolumnlist must contain the same number of new column names as there are columns in columnlist.

replace specifies that the columns in columnlist be converted to numeric columns.

Options for _h2oframe _tostring

Either generate() or replace must be specified.

generate(newcolumnlist) specifies that a new column be created for each column in columnlist. newcolumnlist must contain the same number of new column names as there are columns in columnlist.

replace specifies that the columns in columnlist be converted to string columns.

Examples

 Setup
     . webuse hbp2, clear
     . _h2oframe _put, into(hbp2)
     . _h2oframe _change hbp2
     . _h2oframe _describe

 Create categorical column gender based on the column sex
     . _h2oframe _toenum sex, generate(gender)

 Convert the column sex to a categorical column
     . _h2oframe _encode sex

 Describe the result
     . _h2oframe _describe

 -----------------------------------------------------------------------------------
 Setup
     . webuse destring1, clear
     . _h2oframe _put, into(destring1)
     . _h2oframe _change destring1
     . _h2oframe _describe

 Generate numeric columns from the string columns
     . _h2oframe _tonumeric id num code total income, generate(id2 num2 code2 total2 income2)

 Convert string columns to numeric columns, replacing the original string columns
     . _h2oframe _tonumeric id num code total income, replace

 Describe the result
     . _h2oframe _describe

 -----------------------------------------------------------------------------------
 Setup
     . webuse tostring, clear
     . _h2oframe _put, into(tostring)
     . _h2oframe _change tostring
     . _h2oframe _describe

 Generate string columns from the numeric columns year and day
     . _h2oframe _tostring year day, generate(year2 day2)

 Convert the numeric columns year and day to string columns, replacing the original
 string columns
     . _h2oframe _tostring year day, replace

 Describe the result
     . _h2oframe _describe