pasteByRowOrdered {jamba} | R Documentation |
Paste data.frame rows into an ordered factor
Description
Paste data.frame rows into an ordered factor
Usage
pasteByRowOrdered(
x,
sep = "_",
na.rm = TRUE,
condenseBlanks = TRUE,
includeNames = FALSE,
keepOrder = FALSE,
byCols = seq_len(ncol(x)),
na.last = TRUE,
...
)
Arguments
x |
|
sep |
|
na.rm |
|
condenseBlanks |
|
includeNames |
|
keepOrder |
|
byCols |
|
na.last |
|
... |
additional arguments are passed to |
Details
This function is an extension to jamba::pasteByRow()
which
pastes rows from a data.frame
into a character vector. This
function defines factor levels by running jamba::mixedSortDF(unique(x))
and calling jamba::pasteByRow()
on the result. Therefore the
original order of the input x
is maintained while the factor
levels are based upon the appropriate column-based sort.
Note that the ...
additional arguments are
passed to jamba::mixedSortDF()
to customize the column-based
sort order, used to define factor levels. A good way to test the
order of factors is to run jamba::mixedSortDF(unique(x))
with
appropriate arguments, and confirm the rows are ordered as expected.
Note also that jamba::mixedSortDF()
uses jamba::mixedSort()
which itself performs alphanumeric sort in order to keep
values in proper numeric order where possible.
Value
factor
vector whose levels are defined by existing
factor levels, then by sorted values.
See Also
Other jam string functions:
asSize()
,
breaksByVector()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
nameVector()
,
nameVectorN()
,
padInteger()
,
padString()
,
pasteByRow()
,
sizeAsNum()
,
tcount()
,
ucfirst()
Examples
f <- LETTERS;
df <- data.frame(A=f[rep(1:3, each=2)],
B=c(NA, f[3]),
C=c(NA, NA, f[2]))
df
# note that output is consistent with mixedSortDF()
jamba::mixedSortDF(df)
jamba::pasteByRowOrdered(df)
jamba::mixedSortDF(df, na.last=FALSE)
jamba::pasteByRowOrdered(df, na.last=FALSE)
jamba::mixedSortDF(df, byCols=c(3, 2, 1))
jamba::pasteByRowOrdered(df, byCols=c(3, 2, 1))
df1 <- data.frame(group=rep(c("Control", "ABC1"), each=6),
time=rep(c("Hour2", "Hour10"), each=3),
rep=paste0("Rep", 1:3))
# default will sort each column alphanumerically
pasteByRowOrdered(df1)
# keepOrder=TRUE will honor existing order of character columns
pasteByRowOrdered(df1, keepOrder=TRUE)