# [R] string

Ivan Calandra ivan.calandra at uni-hamburg.de
Tue Dec 7 16:52:07 CET 2010

```It took me quite some time to understand the difference between sep and
collapse.

The examples in Phil Spector's book (2008) helped me to get it:

paste(c('X','Y'), 1:5, sep='_')
"X_1" "Y_2" "X_3" "Y_4" "X_5"
paste(c('X','Y'), 1:5, collapse='|')  ## sep=" " by default
[1] "X 1|Y 2|X 3|Y 4|X 5"
paste(c('X','Y'), 1:5, sep='_', collapse='|')
[1] "X_1|Y_2|X_3|Y_4|X_5"

Ivan

Le 12/7/2010 16:38, (Ted Harding) a écrit :
> Ivan's advice is good, but understanding clearly what
> "character string to separate the results" might mean is
> a bit tricky!
>
> Example:
>
>    cvec<- c("J","e"," ","m","'","a","p","p","e","l","l","e",
>              " ","B","e","n","o","i","t")
>    cstring<- paste(cvec,collapse="")
>    cstring
>    # [1] "Je m'appelle Benoit"
>
> Now try it without the 'collapse=""'.
>
> Hoping this helps,
> Ted.
>
> On 07-Dec-10 15:19:39, Ivan Calandra wrote:
>> Hi,
>> If I understand what you mean (no example...), see ?paste and the
>> collpase argument
>> Ivan
>>
>> Le 12/7/2010 16:11, Benoit Wastine a écrit :
>>> Hi,
>>>
>>> I'm running R 2.11
>>> Does anyone know if it possible to transform one character vector to
>>> one character string ?
>>>
>>> Many thanks
>>> Benoit
>> --
>> Ivan CALANDRA
> --------------------------------------------------------------------
> E-Mail: (Ted Harding)<ted.harding at wlandres.net>
> Fax-to-email: +44 (0)870 094 0861
> Date: 07-Dec-10                                       Time: 15:38:44
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

```