What is the difference between paste/paste0 and str_c?

徘徊边缘 提交于 2019-12-04 09:35:27

paste0(..., collapse = NULL)is a wrapper for paste(..., sep = "", collapse = NULL), which means there is no separator. In other words, with paste0() you can not apply some sort of separator, while you do have that option with paste(), whereas a single space is the default.

str_c(..., sep = "", collapse = NULL) is equivalent to paste(), which means you do have the option to customize your desired separator. The difference is for str_c() the default is no separator, so it acts just like paste0() as a default.

Paste() and paste0() are both functions from the base package, whereas str_c() comes from the stringr package.

I did not test/microbenchmark it, but from my experience I do agree to Ryan str_c() is generally faster.

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