Learn R Programming

reader (version 1.0.6)

find.id.col: Find which column in a dataframe contains a specified set of values.

Description

Starting with a list of ids, each column is searched. The column with the highest non-zero percentage matching is assumed to correspond to the id list. The search terminates early if a perfect match is found. Useful for assembling annotation from multiple sources.

Usage

find.id.col(frame, ids, ret = c("col", "maxpc", "index", "result"))

Arguments

frame
a data.frame, or similarly 2 dimensional object which might contain ids
ids
a vector of IDs/value that might be found in at least 1 column of frame
ret
specify what should be returned, see values

Value

ret can specify a list returning, 'col': the column number (col=0 for rownames) with the best match; 'maxpc': the percentage of ids found in the best matching column; 'index': the matching vector that maps the frame rows onto ids; 'results': the (sub)set of ids found in frame. NAs given for ids not found

Examples

Run this code
new.frame <- data.frame(day=c("M","T","W"),time=c(9,12,3),staff=c("Mary","Jane","John"))
staff.ids <- c("Mark","Jane","John","Andrew","Sally","Mary")
new.frame; staff.ids; find.id.col(new.frame,staff.ids)

Run the code above in your browser using DataLab