(Sorry for the double post.)

On Tue, 4 Jul 2023 10:14:43 +0300
Ivan Krylov <krylov.r...@gmail.com> wrote:

> Try replacing the _second_ paste() in the example above with a c().

What I had forgotten to mention is that you also need to replace the
initial assignment

>  string=""

with the following:

   string = character()

(NULL and c(), as mentioned by Rui, are also valid options here.)

If you don't do that, the empty string remains an element in the
resulting vector c('', 'xxx1', 'xxx2'), which is not the desired
result. It's awkward to build data structures in an iterative manner,
which is why solutions like Rui's paste0("xxx", 1:2) are considered
more idiomatic.

-- 
Best regards,
Ivan

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to