问题
I was working with the paste command in R, when I found that
a <- c("something", "to", "paste")
paste(a, sep="_")
produces the output
# [1] "something" "to" "paste"
Which is same as when I print "a"
# [1] "something" "to" "paste"
So what effect does the sep have on the paste command in R?
回答1:
sep is more generally applicable when you have more than two vectors of length greater than 1. If you were looking to get "something_to_paste", then you would be looking for the collapse argument.
Try the following to get a sense of what the sep argument does:
paste(a, 1:3, sep = "_")
# [1] "something_1" "to_2" "paste_3"
and compare it to collapse:
paste(a, collapse = "_")
# [1] "something_to_paste"
来源:https://stackoverflow.com/questions/27123597/what-is-the-use-of-sep-in-paste-command-of-r