Turn a named vector into a vector of names prefixed by values
Source:R/val_labels.R
names_prefixed_by_values.Rd
Turn a named vector into a vector of names prefixed by values
Examples
df <- dplyr::tibble(
c1 = labelled(c("M", "M", "F"), c(Male = "M", Female = "F")),
c2 = labelled(c(1, 1, 2), c(Yes = 1, No = 2))
)
val_labels(df$c1)
#> Male Female
#> "M" "F"
val_labels(df$c1) %>% names_prefixed_by_values()
#> Male Female
#> "[M] Male" "[F] Female"
val_labels(df)
#> $c1
#> Male Female
#> "M" "F"
#>
#> $c2
#> Yes No
#> 1 2
#>
val_labels(df) %>% names_prefixed_by_values()
#> $c1
#> Male Female
#> "[M] Male" "[F] Female"
#>
#> $c2
#> Yes No
#> "[1] Yes" "[2] No"
#>