[R] quiry on paste() function

Gabor Grothendieck ggrothendieck at gmail.com
Fri Oct 29 14:06:44 CEST 2010


On Fri, Oct 29, 2010 at 4:49 AM, Ron Michael <ron_michael70 at yahoo.com> wrote:
> Hi all, I want to club different objects (character type) to a single one and using paste() function that can be done happily. However the problem with paste function is the separator field is unique for all underlying objects. If I put separator as "-" then this will come in between all underlying objects which are to be clubbed.
>
> Therefore I am wondering whether there is any mechanism to put different separators for different places. Trivially this can be done by applying paste() function repeatedly. However I feel there must be some single mechanism for doing that.
>
> Here is one example, where I apply paste() function twice to incorporate 2 different separators:
>> paste(paste("a", "b", sep=","), "c", sep=":")
> [1] "a,b:c"
>
> Can the same thing be done using paste() function once? something like:
> paste("a", "b", "c", sep=c(",", ":")) # this put 1st separator everywhere which is not intended
>

Try sprintf instead:

   sprintf("%s,%s:%s", "a", "b", "c")


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list