chr.omit: Omit Strings

View source: R/chr.omit.R

chr.omitR Documentation

Omit Strings

Description

This function omits user-specified values or strings from a numeric vector, character vector or factor.

Usage

chr.omit(x, omit = "", na.omit = FALSE, check = TRUE)

Arguments

x

a numeric vector, character vector or factor.

omit

a numeric vector or character vector indicating values or strings to be omitted from the vector x, the default setting is the empty strings "".

na.omit

logical: if TRUE, missing values (NA) are also omitted from the vector.

check

logical: if TRUE (default), argument specification is checked.

Value

Returns a numeric vector, character vector or factor with values or strings specified in omit omitted from the vector specified in x.

Author(s)

Takuya Yanagida

See Also

chr.color, chr.grep, chr.grepl, chr.gsub, chr.trim, chr.trunc

Examples

#————————————————————————————————————————————————————————————————————————————
# Charater Vector

x.chr <- c("a", "", "c", NA, "", "d", "e", NA)

# Example 1: Omit character string ""
chr.omit(x.chr)

# Example 2: Omit character string "" and missing values (NA)
chr.omit(x.chr, na.omit = TRUE)

# Example 3: Omit character string "c" and "e"
chr.omit(x.chr, omit = c("c", "e"))

# Example 4: Omit character string "c", "e", and missing values (NA)
chr.omit(x.chr, omit = c("c", "e"), na.omit = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Numeric Vector

x.num <- c(1, 2, NA, 3, 4, 5, NA)

# Example 5: Omit values 2 and 4
chr.omit(x.num, omit = c(2, 4))

# Example 6: Omit values 2, 4, and missing values (NA)
chr.omit(x.num, omit = c(2, 4), na.omit = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Factor

x.factor <- factor(letters[1:10])

# Example 7: Omit factor levels "a", "c", "e", and "g"
chr.omit(x.factor, omit = c("a", "c", "e", "g"))

misty documentation built on Nov. 24, 2026, 5:06 p.m.

Related to chr.omit in misty...