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))
  )
})

Try the tidyfst package in your browser

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

tidyfst documentation built on Sept. 16, 2024, 9:06 a.m.