sort-additives: Sort vector by length or file types of its content

sort_lengthR Documentation

Sort vector by length or file types of its content

Description

Sort the length or file types of the content of a vector

Takes a vector of file names and sorts them by their file extensions (file type)

Usage

sort_length(vec, asc = TRUE)

sort_file_type(files, asc = TRUE)

Arguments

vec

a vector

asc

A logical value indicating whether to sort in ascending (TRUE) or descending (FALSE) order. Default is TRUE.

files

A character vector containing file names to be sorted

Value

vector of items sorted by length

A character vector of sorted file names

Note

This function removes all NAs prior to sorting the vector

Examples

# sort by length of content
x = c("acs","tt","jdssr","h","grab")
sort_length(vec = x) # ascending order of length
sort_length(vec = x, asc = FALSE) # descending order of length


files <- c("doc1.pdf",
  "image.jpg", "house.csv", "notes.txt",
  "patab","doc2.pdf", "data.csv", "pic.png","cotab")
sort_file_type(files)
sort_file_type(files, asc = FALSE)


quickcode documentation built on April 11, 2025, 5:49 p.m.