Learn R Programming

quickcode (version 1.0.6)

sort_length: 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)

Value

vector of items sorted by length

A character vector of sorted file names

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

Examples

Run this code
# 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)

Run the code above in your browser using DataLab