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)
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
# sort by length of content
x = c("acs","tt","jdssr","h","grab")
sort_length(vec = x) # ascending order of length
#> [1] "h" "tt" "acs" "grab" "jdssr"
sort_length(vec = x, asc = FALSE) # descending order of length
#> [1] "jdssr" "grab" "acs" "tt" "h"
files <- c("doc1.pdf",
"image.jpg", "house.csv", "notes.txt",
"patab","doc2.pdf", "data.csv", "pic.png","cotab")
sort_file_type(files)
#> [1] "patab" "cotab" "house.csv" "data.csv" "image.jpg" "doc1.pdf"
#> [7] "doc2.pdf" "pic.png" "notes.txt"
sort_file_type(files, asc = FALSE)
#> [1] "notes.txt" "pic.png" "doc1.pdf" "doc2.pdf" "image.jpg" "house.csv"
#> [7] "data.csv" "patab" "cotab"