tests/testthat/test-impute_dt.R

test_that("impute values", {
  data = data.table(a = c(1,2,NA,2,4),b = c(T,F,T,NA,T))

  expect_equal(
    data %>% impute_dt(),
    data.table(a = c(1,2,2,2,4),b = c(T,F,T,T,T))
  )
  expect_equal(
    data %>% impute_dt(is.numeric,.func = "mean"),
    data.table(a = c(1,2,2.25,2,4),b = c(T,F,T,NA,T))
  )
  expect_equal(
    data %>% impute_dt(is.numeric,.func = "median"),
    data.table(a = c(1,2,2,2,4),b = c(T,F,T,NA,T))
  )
})
hope-data-science/tidyfst documentation built on Sept. 23, 2024, 8:05 p.m.