Skip to content
Prev 384068 / 398502 Next

How to make a vector with string elements without space

As Borris mentioned, paste0 works well for this.

Another option is the sprintf function:

sprintf("c%i", 1:10)

For this example they do the same thing, but as things become more
complicated sometimes you will want paste0 and sometimes sprintf will
be better.

Compare the above to
sprintf("c%02i", 1:10)

Also, you do not say why you want to do this, but one possible reason
is that you have a set of variables in the global workspace named "c1"
through "c10" that you want to loop through.  If this is the case,
then there are better ways.  You can put the variables into a list,
then use lapply, sapply, or the purrr package to loop through them in
much  better ways.
On Sat, May 23, 2020 at 6:26 AM Vahid Borji <vahid.borji65 at gmail.com> wrote: