pasteByRow {jamba} | R Documentation |
Paste data.frame rows into character vector
Description
Paste data.frame rows into a character vector, optionally removing empty fields in order to avoid delimiters being duplicated.
Usage
pasteByRow(
x,
sep = "_",
na.rm = TRUE,
condenseBlanks = TRUE,
includeNames = FALSE,
sepName = ":",
blankGrep = "^[ ]*$",
verbose = FALSE,
...
)
Arguments
x |
|
sep |
|
na.rm |
|
condenseBlanks |
|
includeNames |
|
sepName |
|
blankGrep |
|
verbose |
|
... |
additional arguments are ignored. |
Details
This function is intended to paste data.frame
(or matrix
, or tibble
)
values for each row of data.
It differs from using apply(x, 2, paste)
:
it handles factors without converting to integer factor level numbers.
it also by default removes blank or empty fields, preventing the delimiter from being included multiple times, per the
condenseBlanks
argument.it is notably faster than apply, by means of running
paste()
on each column of data, making the output vectorized, and scaling rather well for largedata.frame
objects.
The output can also include name:value pairs, which can make the output data more self-describing in some circumstances. That said, the most basic usefulness of this function is to create row labels.
Value
character
vector of length nrow(x)
.
See Also
Other jam string functions:
asSize()
,
breaksByVector()
,
fillBlanks()
,
formatInt()
,
gsubOrdered()
,
gsubs()
,
makeNames()
,
nameVector()
,
nameVectorN()
,
padInteger()
,
padString()
,
pasteByRowOrdered()
,
sizeAsNum()
,
tcount()
,
ucfirst()
Examples
# create an example data.frame
a1 <- c("red","blue")[c(1,1,2)];
b1 <- c("yellow","orange")[c(1,2,2)];
d1 <- c("purple","green")[c(1,2,2)];
df2 <- data.frame(a=a1, b=b1, d=d1);
df2;
# the basic output
pasteByRow(df2);
# Now remove an entry to show the empty field is skipped
df2[3,3] <- "";
pasteByRow(df2);
# the output tends to make good rownames
rownames(df2) <- pasteByRow(df2);
# since the data.frame contains colors, we display using
# imageByColors()
withr::with_par(list("mar"=c(5,10,4,2)), {
imageByColors(df2, cellnote=df2);
})