Seeking a unique match of elements in R Programming - char.expand() Function Last Updated : 15 Jul, 2025 Comments Improve Suggest changes Like Article Like Report char.expand() function in R Language is used to seek a unique match of its first argument among the elements of its second. If successful, it returns this element; otherwise, it performs an action specified by the third argument. Syntax: char.expand(input, target, nomatch = stop("no match"))Parameters: input: character string to be expanded target: character vector with the values to be matched against nomatch: an R expression to be evaluated in case expansion was not possible Example 1: Python3 # R program to illustrate # char.expand function # Creating string vector x <- c("sand", "and", "land") # Calling char.expand() function char.expand("a", x, warning("no expand")) char.expand("an", x, warning("no expand")) char.expand("and", x, warning("no expand")) Output : [1] "and" [1] "and" [1] "and" Example 2: Python3 # R program to illustrate # char.expand function # Creating string vector x <- c("sand", "and", "land") # Calling char.expand() function char.expand("G", x, warning("no expand")) Output: [1] NA Warning message: In eval(nomatch) : no expand Comment More infoAdvertise with us Next Article Make Elements of a Vector Unique in R Programming - make.unique() Function K Kanchan_Ray Follow Improve Article Tags : R Language R Vector-Function Similar Reads Make Elements of a Vector Unique in R Programming - make.unique() Function make.unique() function in R Language is used to return elements of a vector with unique names by appending sequence numbers to duplicates. Syntax: make.unique(names, sep)Parameters: names: Character vector with duplicate names sep: Separator to be used  Example 1: Python3 # R program to make uniqu 1 min read Remove Duplicate Elements from an Object in R Programming - unique() Function unique() function in R Language is used to remove duplicated elements/rows from a vector, data frame or array. Syntax: unique(x) Parameters: x: vector, data frame, array or NULL Example 1: Python3 # R program to illustrate # unique function # Initializing some set of numbers x <- c(1:10, 5:9) x # 1 min read Check if Elements of a Vector are non-empty Strings in R Programming - nzchar() Function nzchar() function in R Language is used to test whether elements of a character vector are non-empty strings. Syntax: nzchar(x) Parameters: x: character vector Example 1: Python3 # R program to illustrate # nzchar function # Initializing a character vector x <- c("GFG", "gfg") 1 min read Getting Match of an Element within a Vector in R Programming - charmatch() Function charmatch() function in R Programming Language is used to find matches between two arguments. Syntax: charmatch(x, table, nomatch = NA_integer_) Parameters: x: the values to be matchedtable: the values to be matched againstnomatch: the integer value to be returned at non-matching positionr - charma 1 min read Matching of patterns in a String in R Programming - agrep() Function agrep() function in R Language is used to search for approximate matches to pattern within each element of the given string. Syntax: agrep(pattern, x, ignore.case=FALSE, value=FALSE)Parameters:pattern: Specified pattern which is going to be matched with given elements of the string. x: Specified st 1 min read Replace the First Match of a Pattern from a String in R Programming â sub() Function sub function in R Language is used to replace the first match of a pattern in a string. If there is a vector of string elements, then it will replace the first match of the pattern from all elements. Syntax: sub(pattern, replacement, string, ignore.case=TRUE/FALSE) Parameters: pattern: string to be 1 min read Like