grapes-inorder-grapes: IN ORDER for Character and Numeric Vectors

%inorder%R Documentation

IN ORDER for Character and Numeric Vectors

Description

This function preserves the original order (sequence) of character vectors.

Usage

y %inorder% table

Arguments

y

numeric vector that contains the sequence to return

table

character vector, data.table, and/or tibble that has the character values to be checked within

Value

character vector with the characters in the original sequence

Author(s)

John Wallace (Stack Overflow R code), Irucka Embry

Source

R - preserve order when using matching operators (

Examples


# Examples (from the Source)

LETTERS[1:26 %in% 4:1]

LETTERS[1:26 %inorder% 4:1]



LETTERS[1:26 %in% 3:-5]

LETTERS[1:26 %inorder% 3:-5]


data.frame(letters, LETTERS)[1:5 %in% 3:-5, ] 

data.frame(letters, LETTERS)[1:5 %inorder% 3:-5, ]


library(data.table)

data.table(letters, LETTERS)[1:5 %inorder% 3:-5, ] 


library(tibble)

tibble(letters, LETTERS)[1:5 %inorder% 3:-5, ]






iemisc documentation built on Sept. 25, 2023, 5:09 p.m.