What is the use of 'sep' in paste command of R? [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-10 12:27:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!