[英]How to add new categorical variable in h2o data frame
我正在嘗試在框架h2o中添加新的分類變量。 我已根據一些要求創建了一個新變量,並且試圖將新值添加到h2o框架中,但出現錯誤。
要添加的新變量:
late_arrival <- with(flights,
ifelse(arr_delay>=30,1,
ifelse(arr_delay<30,0,NA)))
table(late_arrival)
我正在嘗試使用現有的h2o框架對其進行變異,以添加此新變量:
flights_new <- select(flights.hex) %>%
mutate(late_arrival)
UseMethod(“ select_”)中的錯誤:沒有將適用於'select_'的適用方法應用於類“ H2OFrame”的對象
我也嘗試過collect
功能:
flights_new <- select (flights.hex, late_arrival) %>% collect()
UseMethod(“ select_”)中的錯誤:沒有將適用於'select_'的適用方法應用於類“ 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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.