column.salvage: Change column name in different form to desired form.

Description Usage Arguments Value Author(s) Examples

View source: R/reader.R

Description

Searches for possible equivalents for a desired column in a dataframe and replaces first name match with desired name. Useful when parsing different annotation files which may have standard columns with slightly different names, e.g, Gender=SEX=sex=M/F, or ID=id=ids=samples=subjectID

Usage

1
column.salvage(frame, desired, testfor, ignore.case = TRUE)

Arguments

frame

a dataframe or matrix with column names

desired

the column name wanted

testfor

possible alternate forms of the desired column name

ignore.case

whether to ignore the upper/lower case of the column names

Value

returns the original dataframe with the target column renamed

Author(s)

Nicholas Cooper nick.cooper@cimr.cam.ac.uk

Examples

1
2
3
4
5
6
7
df <- data.frame(Sex=c("M","F","F"),time=c(9,12,3),ID=c("ID3121","ID3122","ID2124"))
# standard example
new.df <- column.salvage(df,"sex",c("gender","sex","M/F")); df; new.df
# exact column already present so no change
new.df <- column.salvage(df,"ID",c("ID","id","ids","samples","subjectID")); df; new.df
# ignore case==TRUE potentially results in not finding desired column:
new.df <- column.salvage(df,"sex",c("gender","sex","M/F"),ignore.case=FALSE); df; new.df

reader documentation built on May 2, 2019, 9:27 a.m.