tests/test-empty_array.R

if (require(RUnit)) {
  library(FeatureHashing)
  df <- data.frame(a = rnorm(3), b = c("1,2", "1,,3", ",2,3"), stringsAsFactors = FALSE)
  m <- hashed.model.matrix(~ a * split(b), df, create.mapping = TRUE)
  mapping <- attr(m, "mapping")
  checkTrue(!"b" %in% ls(mapping), "the output contains the column corresponding to empty string")
  df$b <- factor(df$b)
  m <- hashed.model.matrix(~ a * split(b), df, create.mapping = TRUE)
  mapping <- attr(m, "mapping")
  checkTrue(!"b" %in% ls(mapping), "the output contains the column corresponding to empty string")
}

Try the FeatureHashing package in your browser

Any scripts or data that you put into this service are public.

FeatureHashing documentation built on Oct. 31, 2022, 1:06 a.m.