0

I want to paste elements of a vector together, e.g

vec <- c("a","b","c")

to string <- "a,b,c"

I tried paste0(vec, sep =",", collapse= "")

but the output is string <- "a,b,c,"

What is the correct way to do this?

DonDyck
  • 1,451
  • 5
  • 20
  • 35

1 Answers1

6

Use it like this:

paste0(vec, collapse=",")

the "collapse" argument specifies the value to use when collapsing the values into a single string

RichAtMango
  • 376
  • 1
  • 6