renameColumn: Rename columns in a data.frame, matrix, tibble, or GRanges...

renameColumnR Documentation

Rename columns in a data.frame, matrix, tibble, or GRanges object

Description

Rename columns in a data.frame, matrix, tibble, or GRanges object

Usage

renameColumn(x, from, to, verbose = FALSE, ...)

Arguments

x

data.frame, matrix, tbl, or GRanges equivalent object. It will work on any object for which colnames() is defined.

from

character vector of colnames expected to be in x. Any values that do not match colnames(x) are ignored.

to

character vector with length(to) == length(from) corresponding to the target name for any colnames that match from.

Details

This function is intended to rename one or more columns in a data.frame, matrix, tibble, or GRanges related object. It will gracefully ignore columns which do not match, in order to make it possible to call the function again without problem.

This function will also recognize input objects GRanges, ucscData, and IRanges, which store annotation in DataFrame accessible via IRanges::values(). Note the IRanges package is required, for its generic function values().

The values supplied in to and from are converted from factor to character to avoid coersion by R to integer, which was noted in output prior to jamba version ⁠0.0.72.900⁠.

Value

data.frame or object equivalent to the input x, with columns from renamed to values in to. For genomic ranges objects such as GRanges and IRanges, the colnames are updated in IRanges::values(x).

See Also

Other jam practical functions: breakDensity(), checkLightMode(), check_pkg_installed(), colNum2excelName(), color_dither(), diff_functions(), exp2signed(), fileInfo(), fixYellow(), getAxisLabel(), handleArgsText(), heads(), isFALSEV(), isTRUEV(), jamba, jargs(), kable_coloring(), lldf(), log2signed(), make_html_styles(), make_styles(), match_unique(), mergeAllXY(), middle(), minorLogTicks(), newestFile(), printDebug(), rmInfinite(), rmNAs(), rmNA(), rmNULL(), sclass(), sdim(), setPrompt()

Examples

df <- data.frame(A=1:5, B=6:10, C=11:15);
df;
df2 <- renameColumn(df,
   from=c("A","C"),
   to=c("a_new", "c_new"));
df2;
df3 <- renameColumn(df2,
   from=c("A","C","B"),
   to=c("a_new", "c_new","b_new"));
df3;


jmw86069/jamba documentation built on March 26, 2024, 5:26 a.m.