Being new to R, can someone please explain the difference between paste()
and paste0()
, what I had understood from some post is that
paste0("a", "b") === paste("a", "b", sep="")
Even I tried something like this
a <- c("a","b","c")
b <- c("y","w","q")
paste(a,b,sep = "_")
**output**
"a_y" "b_w" "c_q"
using paste0()
a <- c("a","b","c")
b <- c("y","w","q")
paste0(a,b,sep = "_")
**output**
"ay_" "bw_" "cq_"
Is it just that paste()
uses separator between elements and paste0()
uses separator after the elements?
paste0
doesn't have asep
parameter. Trypaste0(a,b,blabla = "_")
– David Arenburg Mar 29 '16 at 9:05?paste
: paste0(..., collapse) is equivalent to paste(..., sep = "", collapse), slightly more efficiently. – erc Mar 29 '16 at 9:05paste
instead ofpaste0
if you want to use a separator. The whole purpose of usingpaste0
is in order to have the separator predefined. This is a classic XY problem. – David Arenburg Mar 29 '16 at 9:13paste0
won't be correctly interpreted byexpression
(tryplot(0:1, 0:1, main=expression(paste(delta, "=3")))
and thenplot(0:1, 0:1, main=expression(paste0(delta, "=3")))
) – Cath Jul 17 '17 at 7:15