Skip to contents

Adds the percentage of missing values per row

Usage

add_percentage_missing(
  dataset,
  column_name = "percentage_missing",
  kobo_survey = NULL,
  type_to_include = c("integer", "date", "text", "select_one", "select_multiple")
)

Arguments

dataset

A dataset to add the percentage of missing values

column_name

string variable with the name of the new column to be created, default is percentage_missing

kobo_survey

Kobo survey sheet.

type_to_include

Types (from KOBO) to be included in the columns default are integer, date, text, select_one and select_multiple.

Value

a dataset with the one additional column with the percentage of missing value

Examples

## Define data 
data_test <- data.frame(
  uuid = c(1:3),
  col_1 = c(1:3),
  col_2 = c(NA, NA, "expenditures"),
  col_3 = c("with need", NA, "with need"),
  col_4 = c("food health school", NA, "food"),
  col_4.food = c(1, NA, 1),
  col_4.health = c(1, NA, 0),
  col_4.school = c(1, NA, 0))

# Define questionnaire
kobo_survey <- data.frame(
  type = c( "uuid",
            "integer",
            "select_one choice2",
            "select_one choice3",
            "select_multiple choice4"  ),
  name = c("uuid", "col_1", "col_2", "col_3", "col_4"))

data_test |>
  add_percentage_missing( kobo_survey = kobo_survey,
                          type_to_include = c("integer", "select_one",
                                              "select_multiple")) |>
  knitr::kable()
#> 
#> 
#> | uuid| col_1|col_2        |col_3     |col_4              | col_4.food| col_4.health| col_4.school| percentage_missing|
#> |----:|-----:|:------------|:---------|:------------------|----------:|------------:|------------:|------------------:|
#> |    1|     1|NA           |with need |food health school |          1|            1|            1|               0.25|
#> |    2|     2|NA           |NA        |NA                 |         NA|           NA|           NA|               0.75|
#> |    3|     3|expenditures |with need |food               |          1|            0|            0|               0.00|

data_test |>
  add_percentage_missing() |>
  knitr::kable()
#> 
#> 
#> | uuid| col_1|col_2        |col_3     |col_4              | col_4.food| col_4.health| col_4.school| percentage_missing|
#> |----:|-----:|:------------|:---------|:------------------|----------:|------------:|------------:|------------------:|
#> |    1|     1|NA           |with need |food health school |          1|            1|            1|              0.125|
#> |    2|     2|NA           |NA        |NA                 |         NA|           NA|           NA|              0.750|
#> |    3|     3|expenditures |with need |food               |          1|            0|            0|              0.000|