test_that("extract from data frame", {
x <- c(1, 2, NA, 3, NaN, 4, NA, 5, Inf, -Inf, 6, 7)
expect_identical(
replace_nan_inf(x),
c(1, 2, NA, 3, NA, 4, NA, 5, NA, NA, 6, 7)
)
# a data frame
df <- data.frame(
x = c(1, NA, 5, Inf, 2, NA),
y = c(3, NaN, 4, -Inf, 6, 7),
stringsAsFactors = FALSE
)
expect_identical(
replace_nan_inf(df),
structure(
list(
x = c(1, NA, 5, NA, 2, NA),
y = c(3, NA, 4, NA, 6, 7)
),
row.names = c(NA, -6L),
class = "data.frame"
)
)
expect_identical(
replace_nan_inf(df, select = starts_with("x")),
structure(
list(
x = c(1, NA, 5, NA, 2, NA),
y = c(3, NaN, 4, -Inf, 6, 7)
),
row.names = c(NA, -6L),
class = "data.frame"
)
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.