Debian Codegraph @

man/sort_levels_values.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/cutree.dendrogram.R
3 \name{sort_levels_values}
4 \alias{sort_levels_values}
5 \title{Sort the values level in a vector}
6 \usage{
7 sort_levels_values(
8 x,
9 MARGIN = 2,
10 decreasing = FALSE,
11 force_integer = FALSE,
12 warn = dendextend_options("warn"),
13 ...
14 )
15 }
16 \arguments{
17 \item{x}{a numeric vector.}
18
19 \item{MARGIN}{passed to \link{apply}. It is a vector giving the subscripts
20 which the function will be applied over.
21 E.g., for a matrix 1 indicates rows, 2 indicates columns,
22 c(1, 2) indicates rows and columns. Where X has named dimnames,
23 it can be a character vector selecting dimension names.}
24
25 \item{decreasing}{logical (FALSE). Should the sort be increasing or decreasing?}
26
27 \item{force_integer}{logical (FALSE). Should the values returned be integers?}
28
29 \item{warn}{logical (default from dendextend_options("warn") is FALSE).
30 Set if warning are to be issued, it is safer to keep this at TRUE,
31 but for keeping the noise down, the default is FALSE.
32 (for example when x had NA values in it)}
33
34 \item{...}{ignored.}
35 }
36 \value{
37 if x is an object - it returns logical - is the object of class dendrogram.
38 }
39 \description{
40 Takes a numeric vector and sort its values so that they
41 would be increasing from left to right.
42 It is different from \code{\link{sort}} in that the function
43 will only "sort" the values levels, and not the vector itself.
44
45 This function is useful for \link[dendextend]{cutree} - making the
46 sort_cluster_numbers parameter possible. Using that parameter with TRUE
47 makes the clusters id's from cutree to be ordered from left to right.
48 e.g: the left most cluster in the tree will be numbered "1", the one
49 after it will be "2" etc...).
50 }
51 \examples{
52
53 x <- 1:4
54 sort_levels_values(x) # 1 2 3 4
55
56 x <- c(4:1)
57 names(x) <- letters[x]
58 attr(x, "keep_me") <- "a cat"
59 sort_levels_values(x) # 1 2 3 4
60
61 x <- c(4:1, 4, 2)
62 sort_levels_values(x) # 1 2 3 4 1 3
63
64 x <- c(2, 2, 3, 2, 1)
65 sort_levels_values(x) # 1 1 2 1 3
66
67 x <- matrix(16:1, 4, 4)
68 rownames(x) <- letters[1:4]
69 x
70 apply(x, 2, sort_levels_values)
71 }
72 \seealso{
73 \code{\link{sort}}, \code{\link{fac2num}}, \code{\link[dendextend]{cutree}}
74 }