sorted_importance: Importance of Strings

Description Usage Arguments Value Examples

View source: R/sorted_importance.R

Description

Decreasingly sorted frequencies of strings, by default weighted by their length. This function can be used to find the most "important" folder paths in terms of frequency and length.

Usage

1
sorted_importance(x, weighted = TRUE)

Arguments

x

vector of character strings

weighted

if TRUE (default) the frequencies of strings are multiplied by the corresponding string lengths

Value

named integer vector (of class table) containing the decreasingly sorted importance values of the elements in x. The importance of a string is either its frequency in x (if weighted is FALSE) or the product of this frequency and the string length (if weighted is TRUE)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
strings <- c("a", "a", "a", "bc", "bc", "cdefg")

(importance <- kwb.pathdict:::sorted_importance(strings))

# Check that each input element is mentioned in the output
all(unique(strings) %in% names(importance))

# weighted = FALSE just returns the frequencies of strings in x
(importance <- kwb.pathdict:::sorted_importance(strings, weighted = FALSE))

# Check if the sum of frequencies is the number of elements in x
sum(importance) == length(strings)

# You may use the function to assess the "importance" of directory paths
kwb.pathdict:::sorted_importance(dirname(kwb.pathdict:::example_paths()))

KWB-R/kwb.pathdict documentation built on Jan. 13, 2020, 2:24 a.m.