Skip to content

string

6 messages · Benoit Wastine, Jonathan P Daily, David Winsemius +2 more

#
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
#
?paste

collapse = T may be necessary.
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it."
     - Jubal Early, Firefly

r-help-bounces at r-project.org wrote on 12/07/2010 10:11:41 AM:
http://www.R-project.org/posting-guide.html
#
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 :

  
    
#
On Dec 7, 2010, at 10:11 AM, Benoit Wastine wrote:

            
?gsub

Also look at the even more powerful gsubfn package. There is also the  
stringr package.
#
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:
--------------------------------------------------------------------
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 ------------------------------
#
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 :