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 factor is a synonym for _h2oframe toenum.

_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 toenum sex, replace

 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