#
# 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 = ", ")
Run the code above in your browser using DataLab