Created
November 27, 2018 17:53
-
-
Save tomhopper/e64485c0d2f4cc81e26415b6aa61c025 to your computer and use it in GitHub Desktop.
Produce a single string from a character vector of strings in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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