nameslike: nameslike: Find Named Elements, Rows or Columns Using A...

Description Usage Arguments Value Author(s) Examples

View source: R/nameslike.R

Description

nameslike() returns element names of x that match a regular expression

Usage

1
nameslike(pattern, x, DIM = 0, ignore.case = T)

Arguments

pattern

character string containing a regular expression to match

x

an object with named elements along at least one dimension; may be a vector, list, matrix, array, data.frame, table, etc.

DIM

integer indicating dimension to search for names that match the pattern. Switches which function gets called to get the names:

  • 0: names (default); works on vectors, lists and data.frame columns

  • 1: rownames; for rows of data.frames, matrices or arrays

  • 2: colnames; for columns of data.frames, matrices or arrays

  • >2: dimnames; for any case where the dimnames function works, such as matrices or arrays. May be used to access higher order dimensions.

  • NA: dimnames; return results from all dimensions

ignore.case

logical; should case be ignored? Search is case-insensitive by default.

Value

character string, or list of character strings if is.na(DIM), containing names that match the specified pattern. Returns an empty vector if no match is found or dimension is unnamed. Returns NULL if the specified dimension does not exist.

Author(s)

M.W.Rowe, mwr.stats@gmail.com

Examples

1
2
3
4
5
6
7
8
hec <- datasets::HairEyeColor
cat("\nEXAMPLE: HairEyeColor is a table object in the datasets package:",
    "\n\n> dimnames(hec)\n\n")
print(dimnames(hec))
for(DIM in c(0:4,NA)){
   cat('\n> nameslike("bl", HairEyeColor, DIM=', DIM, sep="", "):\n")
   print(nameslike("bl", hec, DIM=DIM))
}

mwrowe/microRutils documentation built on June 12, 2021, 2:41 p.m.