R/jamba-string.r
renameColumn.Rd
Rename columns in a data.frame, matrix, tibble, or GRanges object
renameColumn(x, from, to, verbose = FALSE, ...)
data.frame
, matrix
, tbl
, or GRanges
equivalent
object. It will work on any object for which colnames()
is defined.
character
vector of colnames expected to be in x
.
Any values that do not match colnames(x)
are ignored.
character
vector with length(to) == length(from)
corresponding to the target name for any colnames that
match from
.
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)
.
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
.
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()
df <- data.frame(A=1:5, B=6:10, C=11:15);
df;
#> A B C
#> 1 1 6 11
#> 2 2 7 12
#> 3 3 8 13
#> 4 4 9 14
#> 5 5 10 15
df2 <- renameColumn(df,
from=c("A","C"),
to=c("a_new", "c_new"));
df2;
#> a_new B c_new
#> 1 1 6 11
#> 2 2 7 12
#> 3 3 8 13
#> 4 4 9 14
#> 5 5 10 15
df3 <- renameColumn(df2,
from=c("A","C","B"),
to=c("a_new", "c_new","b_new"));
df3;
#> a_new b_new c_new
#> 1 1 6 11
#> 2 2 7 12
#> 3 3 8 13
#> 4 4 9 14
#> 5 5 10 15