Add a rowwise mean or sum index of specific variables to the dataset.

add_index(data, name, ..., type = "mean", na.rm = TRUE, cast.numeric = FALSE)

Arguments

data

a tibble

name

Name of the index column to compute.

...

Variables used for the index.

type

Type of index to compute. Either "mean" (default) or "sum".

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds. Defaults to TRUE.

cast.numeric

a logical value indicating whether all variables selected for index computation should be converted to numeric. Useful if computing indices from factor variables. Defaults to FALSE.

Value

a tibble

See also

get_reliability() to compute reliability estimates of added index variables.

Examples

WoJ %>% add_index(ethical_flexibility, ethics_1, ethics_2, ethics_3, ethics_4)
#> # A tibble: 1,200 x 16 #> country reach employment temp_contract autonomy_selecti~ autonomy_emphas~ #> <fct> <fct> <chr> <fct> <dbl> <dbl> #> 1 Germany Nation~ Full-time Permanent 5 4 #> 2 Germany Nation~ Full-time Permanent 3 4 #> 3 Switzerl~ Region~ Full-time Permanent 4 4 #> 4 Switzerl~ Local Part-time Permanent 4 5 #> 5 Austria Nation~ Part-time Permanent 4 4 #> 6 Switzerl~ Local Freelancer NA 4 4 #> 7 Germany Local Full-time Permanent 4 4 #> 8 Denmark Nation~ Full-time Permanent 3 3 #> 9 Switzerl~ Local Full-time Permanent 5 5 #> 10 Denmark Nation~ Full-time Permanent 2 4 #> # ... with 1,190 more rows, and 10 more variables: ethics_1 <dbl>, #> # ethics_2 <dbl>, ethics_3 <dbl>, ethics_4 <dbl>, work_experience <dbl>, #> # trust_parliament <dbl>, trust_government <dbl>, trust_parties <dbl>, #> # trust_politicians <dbl>, ethical_flexibility <dbl>
WoJ %>% add_index(ethical_flexibility, ethics_1, ethics_2, ethics_3, ethics_4, type = "sum")
#> # A tibble: 1,200 x 16 #> country reach employment temp_contract autonomy_selecti~ autonomy_emphas~ #> <fct> <fct> <chr> <fct> <dbl> <dbl> #> 1 Germany Nation~ Full-time Permanent 5 4 #> 2 Germany Nation~ Full-time Permanent 3 4 #> 3 Switzerl~ Region~ Full-time Permanent 4 4 #> 4 Switzerl~ Local Part-time Permanent 4 5 #> 5 Austria Nation~ Part-time Permanent 4 4 #> 6 Switzerl~ Local Freelancer NA 4 4 #> 7 Germany Local Full-time Permanent 4 4 #> 8 Denmark Nation~ Full-time Permanent 3 3 #> 9 Switzerl~ Local Full-time Permanent 5 5 #> 10 Denmark Nation~ Full-time Permanent 2 4 #> # ... with 1,190 more rows, and 10 more variables: ethics_1 <dbl>, #> # ethics_2 <dbl>, ethics_3 <dbl>, ethics_4 <dbl>, work_experience <dbl>, #> # trust_parliament <dbl>, trust_government <dbl>, trust_parties <dbl>, #> # trust_politicians <dbl>, ethical_flexibility <dbl>