I am trying to follow the suggestion on question: "Coerce multiple columns to factors at once", but it does not work for an H2OFrame
object, for example:
data <- data.frame(matrix(sample(1:40), 4, 10, dimnames = list(1:4, LETTERS[1:10])))
data.hex <- as.h2o(data, destination_frame = "data.hex")
cols <- c("A", "C", "D", "H")
data.hex[cols] <- lapply(data.hex[cols], factor)
Produces the following error message:
Error in `[<-.H2OFrame`(`*tmp*`, cols, value = list(1L, 1L, 1L, 1L, 1L, :
`value` can only be an H2OFrame object or a numeric or character vector
In addition:
Warning message:
In if (is.na(value)) value <- NA_integer_ else if (!is.numeric(value) && :
the condition has length > 1 and only the first element will be used
If I try to coerce as factor one by one, it works. Another workaround is to coerce as factor first the data.frame
, then convert it into H2OFrame
object, for example:
data[cols] <- lapply(data[cols], factor)
data.hex <- as.h2o(data, destination_frame = "data.hex")
Any explanation why it happens or any better workaround?