Skip to content

Instantly share code, notes, and snippets.

@tomhopper
Created November 27, 2018 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhopper/e64485c0d2f4cc81e26415b6aa61c025 to your computer and use it in GitHub Desktop.
Save tomhopper/e64485c0d2f4cc81e26415b6aa61c025 to your computer and use it in GitHub Desktop.
Produce a single string from a character vector of strings in R
# Set up some test data
my_names <- letters[1:5]
my_names
# [1] "a" "b" "c" "d" "e"
# We want a list, like "a, b, c, d, e"
# Paste the names together
paste(my_names)
# [1] "a" "b" "c" "d" "e"
# Not the result we were looking for
# paste() with the collapse= parameter produces the desired result
paste(my_names, collapse = "")
# [1] "abcde"
paste(my_names, collapse = ", ")
# [1] "a, b, c, d, e"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment