Sort value labels according to values or to labels

sort_val_labels(x, according_to = c("values", "labels"),
  decreasing = FALSE)

# S3 method for haven_labelled
sort_val_labels(x, according_to = c("values",
  "labels"), decreasing = FALSE)

# S3 method for data.frame
sort_val_labels(x, according_to = c("values",
  "labels"), decreasing = FALSE)

Arguments

x

A labelled vector.

according_to

According to values or to labels?

decreasing

In decreasing order?

Examples

v <- labelled(c(1, 2, 3), c(maybe = 2, yes = 1, no = 3)) v
#> <Labelled double> #> [1] 1 2 3 #> #> Labels: #> value label #> 2 maybe #> 1 yes #> 3 no
sort_val_labels(v)
#> <Labelled double> #> [1] 1 2 3 #> #> Labels: #> value label #> 1 yes #> 2 maybe #> 3 no
sort_val_labels(v, decreasing = TRUE)
#> <Labelled double> #> [1] 1 2 3 #> #> Labels: #> value label #> 3 no #> 2 maybe #> 1 yes
sort_val_labels(v, 'l')
#> <Labelled double> #> [1] 1 2 3 #> #> Labels: #> value label #> 2 maybe #> 3 no #> 1 yes
sort_val_labels(v, 'l', TRUE)
#> <Labelled double> #> [1] 1 2 3 #> #> Labels: #> value label #> 1 yes #> 3 no #> 2 maybe