Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在h2o数据框中添加新的分类变量_R_Variables_H2o - Fatal编程技术网

R 如何在h2o数据框中添加新的分类变量

R 如何在h2o数据框中添加新的分类变量,r,variables,h2o,R,Variables,H2o,我试图在框架h2o中添加新的分类变量。 我已经根据一些要求创建了一个新变量,我试图在h2o框架中获得新的值,但我得到了错误 要添加的新变量: late_arrival <- with(flights, ifelse(arr_delay>=30,1, ifelse(arr_delay<30,0,NA))) table(late_arrival) UseMethod(“选择”)中出错: 没有适用于“H2OFrame”类对象的“选择”方法 如何将新的分类变量添加到h2o数据框中

我试图在框架h2o中添加新的分类变量。 我已经根据一些要求创建了一个新变量,我试图在h2o框架中获得新的值,但我得到了错误

要添加的新变量:

late_arrival <- with(flights,
 ifelse(arr_delay>=30,1,
 ifelse(arr_delay<30,0,NA)))
table(late_arrival)
UseMethod(“选择”)中出错: 没有适用于“H2OFrame”类对象的“选择”方法


如何将新的分类变量添加到h2o数据框中?

您可以在将数据加载到h2o群集之前进行此更改,也可以在flight.hex的h2o群集一侧进行内部更改。请参见下面的mtcars示例

# change before loading data into h2o:
mtcars$new_condition <- ifelse(mtcars$mpg >= 20, 1, 
                               ifelse(mtcars$mpg <20, 0, NA))

library(h2o)
h2o.init()

mtcars.hex <- as.h2o(mtcars)

# change when data is inside h2o cluster
mtcars.hex$new_condition2 <- ifelse(mtcars.hex$mpg >= 20, 1, 
                                   ifelse(mtcars.hex$mpg <20, 0, NA))

mtcars.hex

   mpg cyl disp  hp drat    wt  qsec vs am gear carb new_condition new_condition2
1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4             1              1
2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4             1              1
3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1             1              1
4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1             1              1
5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2             0              0
6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1             0              0

[32 rows x 13 columns]
#将数据加载到h2o之前更改:
mtcars$new_条件=20,1,,

ifelse(mtcars$mpg您可以在将数据加载到h2o集群之前进行此更改,也可以在flight.hex上的h2o集群侧进行更改。请参见下面的mtcars示例

# change before loading data into h2o:
mtcars$new_condition <- ifelse(mtcars$mpg >= 20, 1, 
                               ifelse(mtcars$mpg <20, 0, NA))

library(h2o)
h2o.init()

mtcars.hex <- as.h2o(mtcars)

# change when data is inside h2o cluster
mtcars.hex$new_condition2 <- ifelse(mtcars.hex$mpg >= 20, 1, 
                                   ifelse(mtcars.hex$mpg <20, 0, NA))

mtcars.hex

   mpg cyl disp  hp drat    wt  qsec vs am gear carb new_condition new_condition2
1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4             1              1
2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4             1              1
3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1             1              1
4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1             1              1
5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2             0              0
6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1             0              0

[32 rows x 13 columns]
#将数据加载到h2o之前更改:
mtcars$new_条件=20,1,,
ifelse(mtcars$mpg)
# change before loading data into h2o:
mtcars$new_condition <- ifelse(mtcars$mpg >= 20, 1, 
                               ifelse(mtcars$mpg <20, 0, NA))

library(h2o)
h2o.init()

mtcars.hex <- as.h2o(mtcars)

# change when data is inside h2o cluster
mtcars.hex$new_condition2 <- ifelse(mtcars.hex$mpg >= 20, 1, 
                                   ifelse(mtcars.hex$mpg <20, 0, NA))

mtcars.hex

   mpg cyl disp  hp drat    wt  qsec vs am gear carb new_condition new_condition2
1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4             1              1
2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4             1              1
3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1             1              1
4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1             1              1
5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2             0              0
6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1             0              0

[32 rows x 13 columns]