cPaste | R Documentation |
Paste a list of vectors into a character vector, with values delimited by default with a comma.
cPaste(
x,
sep = ",",
doSort = FALSE,
makeUnique = FALSE,
na.rm = FALSE,
keepFactors = FALSE,
checkClass = TRUE,
useBioc = TRUE,
useLegacy = FALSE,
honorFactor = TRUE,
verbose = FALSE,
...
)
x |
input |
sep |
|
doSort |
|
makeUnique |
|
na.rm |
boolean indicating whether to remove NA values from
each vector in the input list. When |
keepFactors |
|
useBioc |
|
useLegacy |
|
honorFactor |
|
... |
additional arguments are passed to |
This function is essentially a wrapper for S4Vectors::unstrsplit()
except that it also optionally applies uniqueness to each vector
in the list, and sorts values in each vector using mixedOrder()
.
The sorting and uniqueness is applied to the unlist
ed vector of
values, which is substantially faster than any apply
family function
equivalent. The uniqueness is performed by uniques()
, which itself
will use S4Vectors::unique()
if available.
character vector with the same names and in the same order
as the input list x
.
Other jam string functions:
asSize()
,
breaksByVector()
,
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
mixedOrder()
,
mixedSortDF()
,
mixedSorts()
,
mixedSort()
,
mmixedOrder()
,
nameVectorN()
,
nameVector()
,
padInteger()
,
padString()
,
pasteByRowOrdered()
,
pasteByRow()
,
sizeAsNum()
,
tcount()
,
ucfirst()
,
uniques()
Other jam list functions:
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
heads()
,
jam_rapply()
,
list2df()
,
mergeAllXY()
,
mixedSorts()
,
rbindList()
,
relist_named()
,
rlengths()
,
sclass()
,
sdim()
,
uniques()
,
unnestList()
L1 <- list(CA=LETTERS[c(1:4,2,7,4,6)], B=letters[c(7:11,9,3)]);
cPaste(L1);
# CA B
# "A,B,C,D,B,G,D,F" "g,h,i,j,k,i,c"
cPaste(L1, doSort=TRUE);
# CA B
# "A,B,B,C,D,D,F,G" "c,g,h,i,i,j,k"
## The sort can be done with convenience function cPasteS()
cPasteS(L1);
# CA B
# "A,B,B,C,D,D,F,G" "c,g,h,i,i,j,k"
## Similarly, makeUnique=TRUE and cPasteU() are the same
cPaste(L1, makeUnique=TRUE);
cPasteU(L1);
# CA B
# "A,B,C,D,G,F" "g,h,i,j,k,c"
## Change the delimiter
cPasteSU(L1, sep="; ")
# CA B
# "A; B; C; D; F; G" "c; g; h; i; j; k"
# test mix of factor and non-factor
L2 <- c(
list(D=factor(letters[1:12],
levels=letters[12:1])),
L1);
L2;
cPasteSU(L2, keepFactors=TRUE);
# tricky example with mix of character and factor
# and factor levels are inconsistent
# end result: factor levels are defined in order they appear
L <- list(entryA=c("miR-112", "miR-12", "miR-112"),
entryB=factor(c("A","B","A","B"),
levels=c("B","A")),
entryC=factor(c("C","A","B","B","C"),
levels=c("A","B","C")),
entryNULL=NULL)
L;
cPaste(L);
cPasteU(L);
# by default keepFactors=FALSE, which means factors are sorted as characters
cPasteS(L);
cPasteSU(L);
# keepFactors=TRUE will keep unique factor levels in the order they appear
# this is the same behavior as unlist(L[c(2,3)]) on a list of factors
cPasteSU(L, keepFactors=TRUE);
levels(unlist(L[c(2,3)]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.