[R] String question

(Ted Harding) Ted.Harding at manchester.ac.uk
Wed Dec 23 12:57:22 CET 2009


On 23-Dec-09 11:40:12, baptiste auguie wrote:
> Isn't paste doing exactly this?
> 
> temp <- c("November", "December","Monday","Tuesday")
> paste(temp, collapse=",")
># "November,December,Monday,Tuesday"
> 
> HTH,
> baptiste

Yes, spot-on! I got involved in the confusion resulting from
the use of "sep" in previous postings.

I think that solves it for Knut!
Ted.

> 2009/12/23 Ted Harding <Ted.Harding at manchester.ac.uk>:
>> On 23-Dec-09 11:08:02, Knut Krueger wrote:
>>> Jim Lemon schrieb:
>>>> Not as easy as I thought it would be, but:
>>>>
>>>> mlist<-as.list(paste("m",1:sample(5:10,1),sep=""))
>>>> do.call("paste",c(mlist,sep=","))
>>>
>>> Hi Jim,
>>> yes it works _:-)
>>>
>>> temp <- c("November", "December","Monday","Tuesday")
>>> length(temp) #getting the length of the vector
>>> string1=do.call("paste",c(as.list(temp),sep=",")) #converting to a
>>> string
>>>
>>> but I have no idea where I could find that documentation ;-)
>>>
>>> Thanks a lot
>>> Knut
>>
>> Interestingly, cat() does the pasting job in the simplest
>> possible way:
>>
>>> temp <- c("November", "December","Monday","Tuesday")
>>> cat(temp,sep=",")
>> November,December,Monday,Tuesday>
>>
>> [copied from the R console; note the trialing ">" which is
>> _the command prompt for the next input -- not part of the
>> _output of cat() ]
>>
>> with output to screen (or to nominated file). But there
>> seems to be no way to persuade cat to *return* this result
>> as a value, which could be assigned to a variable.
>>
>> If there were such a way, that would be a very smooth solution!
>>
>> Ted.
>>
>> --------------------------------------------------------------------
>> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
>> Fax-to-email: +44 (0)870 094 0861
>> Date: 23-Dec-09 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Time: 11:28:47
>> ------------------------------ XFMail ------------------------------
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>>
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 23-Dec-09                                       Time: 11:57:19
------------------------------ XFMail ------------------------------



More information about the R-help mailing list