Create or change contents of column in current H2O frame¶
Syntax¶
Create new column
_h2oframe generate newcolname =exp
Replace contents of existing column
_h2oframe replace oldcolname =exp [if] [in]
Description¶
_h2oframe generate creates a new column. The values of the column are specified by =exp. See Using functions and expressions for more information about specifying expressions with H2O frames.
The new column type is determined by the type of result returned by =exp. A numeric column (real or int) is created if the result is numeric, and a string column is created if the result is a string. See What is an H2O frame? for more information about the data types in an H2O frame.
_h2oframe replace changes the contents of an existing column.
Examples¶
Setup
. webuse genxmpl3
. _h2oframe put, into(genxmpl3)
. _h2oframe change genxmpl3
Create new column age2 containing the values of age squared
. _h2oframe generate age2 = age^2
-----------------------------------------------------------------------------------
Setup
. webuse genxmpl1, clear
. _h2oframe put, into(genxmpl1)
. _h2oframe change genxmpl1
Replace the values in age2 with those of age^2
. _h2oframe replace age2 = age^2
-----------------------------------------------------------------------------------
Setup
. webuse genxmpl2, clear
. _h2oframe put, into(genxmpl2)
. _h2oframe change genxmpl2
Create column upname with the contents of name, but in uppercase
. _h2oframe generate upname = toupper(name)
. _h2oframe get genxmpl2, clear
. list