File: sort_levels_values.Rd

package info (click to toggle)
r-cran-dendextend 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,888 kB
  • sloc: sh: 13; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 2,166 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cutree.dendrogram.R
\name{sort_levels_values}
\alias{sort_levels_values}
\title{Sort the values level in a vector}
\usage{
sort_levels_values(
  x,
  MARGIN = 2,
  decreasing = FALSE,
  force_integer = FALSE,
  warn = dendextend_options("warn"),
  ...
)
}
\arguments{
\item{x}{a numeric vector.}

\item{MARGIN}{passed to \link{apply}. It is a vector giving the subscripts
which the function will be applied over.
 E.g., for a matrix 1 indicates rows, 2 indicates columns,
 c(1, 2) indicates rows and columns. Where X has named dimnames,
 it can be a character vector selecting dimension names.}

\item{decreasing}{logical (FALSE). Should the sort be increasing or decreasing?}

\item{force_integer}{logical (FALSE). Should the values returned be integers?}

\item{warn}{logical (default from dendextend_options("warn") is FALSE).
Set if warning are to be issued, it is safer to keep this at TRUE,
but for keeping the noise down, the default is FALSE.
(for example when x had NA values in it)}

\item{...}{ignored.}
}
\value{
if x is an object - it returns logical - is the object of class dendrogram.
}
\description{
Takes a numeric vector and sort its values so that they
would be increasing from left to right.
It is different from \code{\link{sort}} in that the function
will only "sort" the values levels, and not the vector itself.

This function is useful for \link[dendextend]{cutree} - making the
sort_cluster_numbers parameter possible. Using that parameter with TRUE
makes the clusters id's from cutree to be ordered from left to right.
e.g: the left most cluster in the tree will be numbered "1", the one
after it will be "2" etc...).
}
\examples{

x <- 1:4
sort_levels_values(x) # 1 2 3 4

x <- c(4:1)
names(x) <- letters[x]
attr(x, "keep_me") <- "a cat"
sort_levels_values(x) # 1 2 3 4

x <- c(4:1, 4, 2)
sort_levels_values(x) # 1 2 3 4 1 3

x <- c(2, 2, 3, 2, 1)
sort_levels_values(x) # 1 1 2 1 3

x <- matrix(16:1, 4, 4)
rownames(x) <- letters[1:4]
x
apply(x, 2, sort_levels_values)
}
\seealso{
\code{\link{sort}}, \code{\link{fac2num}}, \code{\link[dendextend]{cutree}}
}