Re: [R] String concatenation

From: Andy Fugard <a.fugard_at_ed.ac.uk>
Date: Sat, 28 Jun 2008 17:13:34 +0100

On 28 Jun 2008, at 16:20, Peng Jiang wrote:

> Hi, Andy
> I am a little confused, why don't you just use paste() directly?
>
> > paste("12","3","45",sep="")
>
> produce the same result with your concat.

The problem is that I have a vector, not those individual arguments.

But the collapse argument does the trick - ta.

A

>
>
> regards .
> On 2008-6-28, at 下午7:44, Andy Fugard wrote:
>
>> Hi,
>>
>> Is the following function built in somewhere?
>>
>> concat = function(v) {
>> res = ""
>>
>> for (i in 1:length(v))
>> res = paste(res,v[i],sep="")
>>
>> res
>> }
>>
>> e.g.
>>
>> > concat(c("12","3","45"))
>> [1] "12345"
>>
>> Cheers,
>>
>> Andy
>>
>> --
>> Andy Fugard, Postgraduate Research Student
>> Psychology (Room F3), The University of Edinburgh,
>> 7 George Square, Edinburgh EH8 9JZ, UK
>> Mobile: +44 (0)78 123 87190 http://www.possibly.me.uk
>>
>> The University of Edinburgh is a charitable body, registered in
>> Scotland, with registration number SC005336.
>>
>> ______________________________________________
>> 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.
>
> -----------------------------------------------
> Peng Jiang
> 江鹏
> Ph.D. Candidate
> Antai College of Economics & Management
> 安泰经济管理学院
> Department of Mathematics
> 数学系
> Shanghai Jiaotong University (Minhang Campus)
> 800 Dongchuan Road

> 200240 Shanghai
> P. R. China
>
>

--
Andy Fugard, Postgraduate Research Student
Psychology (Room F3), The University of Edinburgh,
   7 George Square, Edinburgh EH8 9JZ, UK
Mobile: +44 (0)78 123 87190   http://www.possibly.me.uk



-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

______________________________________________
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.
Received on Sun 29 Jun 2008 - 06:00:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 29 Jun 2008 - 07:31:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive