| paste_conditional {stringmagic} | R Documentation | 
Paste a string vector conditionally
Description
Easily reconstruct a string vector that has been split with string_split2df().
Usage
paste_conditional(x, id, sep = " ", names = TRUE, sort = TRUE)
Arguments
| x | A character vector or a formula. If a vector: it represents the
values to be pasted together.
If a formula, it must be of the form
 | 
| id | A vector of identifiers, a list of identifiers (can be a data frame),
or a  When  | 
| sep | A character scalar, default is  | 
| names | Logical scalar, default is  | 
| sort | Logical scalar, default is  | 
Value
Returns a character vector. If the argument names is TRUE (default), the vector will have
names equal to the values of the identifiers.
Examples
#
# let's paste together the letters of the alphabet
# first we create the identifier
id = rep(1:2, each = 13)
setNames(id, letters)
# now we conditionally paste together the letters
paste_conditional(letters, id, "")
#
# using a formula
# we create a small data set based on mtcars
base_cars = within(mtcars, carname <- row.names(mtcars))
base_cars = head(base_cars, 10)
# we use two identifiers
paste_conditional(carname ~ gear + carb, base_cars, sep = ", ")