library (surveyreader)
library(testthat)
context("Convert 4-level agreement (for-against) categories.")
test_that("correct character conversion takes place", {
expect_equal( rescale_for_against_4 (column =
c("Strongly in favour",
"Fairly in favour",
"Fairly opposed",
"Strongly opposed",
"DK", "NT/NV"),
na_labels = "default",
return_class = "character"),
c("strongly_for", "for",
"against", "strongly_against",
NA, NA)
)})
test_that("correct numeric conversion takes place", {
expect_equal( rescale_for_against_4 (column =
c("Strongly in favour",
"Fairly in favour",
"Fairly opposed",
"Strongly opposed",
"DK", "NT/NV"),
na_labels = "default",
return_class = "numeric"),
c(2, 1, -1, -2, NA, NA)
)
})
test_that("function behind wrapper works", {
expect_equal( rescale_categories (column =
c("Strongly in favour",
"Fairly in favour",
"Fairly opposed",
"Strongly opposed",
"DK", "NT/NV"),
from = c("Strongly in favour",
"Fairly in favour",
"Fairly opposed",
"Strongly opposed"),
to = c(2,1,-1, -2),
na_labels = "default",
return_class = "numeric"),
c(2, 1, -1, -2, NA, NA)
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.