collapse {utilitiesR} | R Documentation |
This is mainly used to concatenate elements of a vector
into a string. It is just a wrapper around
paste
with collapse=”, so if you
find yourself specifying both sep
and
collapse
to collapse
, just use paste
instead!
collapse(..., sep = "", collapse = "")
... |
vector/string(s) to paste, see
|
sep |
string to separate corresponding terms in the
arguments in |
collapse |
string to separate each element of the
result vector. Default ”. See
|
the input strings collapsed and pasted.
%+%
, shorthand for pasting with separator
”.
collapse(letters) # "abcdefghijklmnopqrstuvwxyz" collapse(letters[1:10], collapse='|') # "a|b|c|d|e|f|g|h|i|j" collapse(letters[1:10], 1:10) # "a1b2c3d4e5f6g7h8i9j10" collapse(letters[1:10], 1:10, sep='.') # "a.1b.2c.3d.4e.5f.6g.7h.8i.9j.10" # Note - if you supply both collapse and sep then you may as well use paste.