nameVector | R Documentation |
assign unique names for a vector
nameVector(x, y = NULL, makeNamesFunc = makeNames, ...)
x |
vector input, or data.frame, matrix, or tibble with two columns, the second column is used to name values in the first column. |
y |
NULL or character vector of names. If NULL then x is used.
Note that y is recycled to the length of x, prior to being sent
to the makeNamesFunc.
In fringe cases, y can be a matrix, data.frame, or tibble, in which
case |
makeNamesFunc |
function to make names unique, by default
|
... |
passed to |
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")])
vector with names defined
Other jam string functions:
asSize()
,
breaksByVector()
,
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
mixedOrder()
,
mixedSortDF()
,
mixedSorts()
,
mixedSort()
,
mmixedOrder()
,
nameVectorN()
,
padInteger()
,
padString()
,
pasteByRowOrdered()
,
pasteByRow()
,
sizeAsNum()
,
tcount()
,
ucfirst()
,
uniques()
# 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);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.