Reputation: 645
I am trying to create a character string that looks something like
"c,1,2,3,4,5,6,7,8"
I am able to get the number part of the string by doing:
paste0(1:200, collapse = ",")
How would I add "c," to the beginning of the result of paste0
? Alternatively, how could I join ",c" end of the result?
Upvotes: 2
Views: 1747
Reputation: 887213
We can wrap with paste
paste0("c(", paste0(1:200, collapse = ","), ")")
Or with sprintf
sprintf("c(%s)", paste0(1:200, collapse=","))
If we need only 'c', then use
sprintf("c,%s", paste0(1:200, collapse = ","))
Upvotes: 6
Reputation: 269664
Create a vector made up of c
and 1:8
and then use toString
:
toString(c("c", 1:8))
## [1] "c, 1, 2, 3, 4, 5, 6, 7, 8"
Upvotes: 2
Reputation: 474
You just want the string c, not the function right?
paste0(c("c", 1:8), collapse = ",")
Upvotes: 4