Manage levels of a categorical column in the current H2O frame¶
Syntax¶
List all levels of a categorical column
_h2oframe levelsof columnname [, options]
Set the base level of a categorical column
_h2oframe baselevel columnname baselevel
Assign new levels of a categorical column
_h2oframe recodelevel columnname level1 [level2 [...]]
columnname is the name of a categorical column with type enum in the current H2O frame.
options Description
-----------------------------------------------------------------------------------
clean display levels without compound double quotes
separate(separator) separator to serve as punctuation for the values of returned
list; default is a space
-----------------------------------------------------------------------------------
Description¶
_h2oframe levelsof displays the levels of the categorical column columnname. columnname must be an enum column.
_h2oframe baselevel specifies the base level of the categorical column columnname. columnname must be an enum column, and baselevel must be an existing level of columnname.
_h2oframe recodelevel assigns new levels to the categorical column columnname. The number of new levels specified (level1, level2, …) must be equal to the number of levels in column columnname.
Options¶
Options for _h2oframe levelsof¶
clean displays levels without compound double quotes. By default, each distinct level is displayed within compound double quotes, because these are the most general delimiters. If you know that the levels in columnname do not include embedded spaces or embedded quotes, then clean is an appropriate option.
separate(separator) specifies a separator to serve as punctuation for the values of the returned list. The default is a space. A useful alternative is a comma.
Examples¶
Setup
. sysuse auto, clear
. _h2oframe put, into(auto)
. _h2oframe change auto
List all levels of column foreign
. _h2oframe levelsof foreign
. display `"`r(levels)'"'
Same as above, but display levels without compound double quotes
. _h2oframe levelsof foreign, clean
. display `"`r(levels)'"'
-----------------------------------------------------------------------------------
Setup
. webuse iris, clear
. _h2oframe put, into(irisframe)
. _h2oframe change irisframe
List all levels of column iris
. _h2oframe levelsof iris
Set the base level of iris to "Virginica"
. _h2oframe baselevel iris "Virginica"
. _h2oframe levelsof iris
-----------------------------------------------------------------------------------
Setup
. webuse iris, clear
. _h2oframe put, into(irisframe2)
. _h2oframe change irisframe2
List all levels of column iris
. _h2oframe levelsof iris
Change levels of iris to level1, level2, and level3
. _h2oframe recodelevel iris "level1" "level2" "level3"
. _h2oframe levelsof iris
. display `"`r(levels)'"'
Stored results¶
_h2oframe levelsof stores the following in r():
Scalar
r(r) number of distinct levels
Macro
r(levels) list of distinct levels