nameVector {jamba} | R Documentation |
assign unique names for a vector
Description
assign unique names for a vector
Usage
nameVector(x, y = NULL, makeNamesFunc = makeNames, ...)
Arguments
x |
|
y |
|
makeNamesFunc |
|
... |
passed to |
Details
This function assigns unique names to a vector, if necessary it runs
makeNames
to create unique names. It differs from
setNames
in that it ensures names are unique,
and when no names are supplied, it uses the vector itself to define
names. It is helpful to run this function inside an lapply
function call, which by default maintains names, but does not assign
names if the input data did not already have them.
When used with a data.frame, it is particularly convenient to pull out a named vector of values. For example, log2 fold changes by gene, where the gene symbols are the name of the vector.
nameVector(genedata[,c("Gene","log2FC")])
Value
vector with names defined
See Also
Other jam string functions:
asSize()
,
breaksByVector()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
nameVectorN()
,
padInteger()
,
padString()
,
pasteByRow()
,
pasteByRowOrdered()
,
sizeAsNum()
,
tcount()
,
ucfirst()
Examples
# it generally just creates names from the vector values
nameVector(LETTERS[1:5]);
# if values are replicated, the makeNames() function makes them unique
V <- rep(LETTERS[1:5], each=3);
nameVector(V);
# for a two-column data.frame, it creates a named vector using
# the values in the first column, and names in the second column.
df <- data.frame(seq_along(V), V);
df;
nameVector(df);
# Lastly, admittedly a fringe case, it can take a multi-column data.frame
# to generate labels:
nameVector(V, df);