I’m sure there’s already a solution to this question on here, but for the life of me, I can’t figure out the right way to search for it, so here goes.
Say I’ve got a named vector
vector <- c(a = 1, b = 2, c = 3)
How can I get the following output printed as a string, say using paste
"a=1; b=2; c=3"
>Solution :
You can use paste like so:
paste(names(vector), "=", vector, collapse = "; ")
#[1] "a = 1; b = 2; c = 3"
Or use paste0 if you don’t want the space:
paste0(names(vector), "=", vector, collapse = "; ")
#[1] "a=1; b=2; c=3"