[R] pasting elements of one character vector together

Eik Vettorazzi E.Vettorazzi at uke.de
Tue Sep 20 12:14:07 CEST 2011


Hi marion,
just transpose the matrix:
mm<-matrix(LETTERS[1:20],nrow=5)
paste(t(mm),collapse="")
or - if you want the result seperated by rows

apply(mm,1,paste,collapse="")

cheers

Am 20.09.2011 11:55, schrieb Marion Wenty:
> I have another question concerning the paste command:
> 
> now instead of a vector I would like to paste the elements of a matrix
> together, which works in the same:
> 
> Mypastedmatrix <- paste(Mymatrix,collapse="")
> 
> My problem now is that the program does this BY COLUMN, but I would like to
> have the elements pasted together BY ROW.
> 
> Could anybody help me with this?
> 
> Marion
> 
> 2011/9/19 Marion Wenty <marion.wenty at gmail.com>
> 
>> hello michael and dimitris,
>> yes, this was it!
>> now i understand this collapse-argument.
>> thank you very much.
>> marion
>>
>>
>> 2011/9/19 Dimitris Rizopoulos <d.rizopoulos at erasmusmc.nl>
>>
>>> Try this:
>>>
>>> object <- c("Hello", "World")
>>> paste(object, collapse = " ")
>>>
>>>
>>> I hope it helps.
>>>
>>> Best,
>>> Dimitris
>>>
>>>
>>>
>>>
>>> On 9/19/2011 3:58 PM, Marion Wenty wrote:
>>>
>>>> hello,
>>>>
>>>> i am familiar with the paste command with which i can paste for exaple:
>>>>
>>>> object<- "Hello"
>>>> paste(object,"World")
>>>>
>>>> now i would like to be able to paste all the elements of the same vector
>>>> together e.g:
>>>>
>>>> object<- c("Hello","World")
>>>>
>>>> getting as a result also:
>>>>
>>>> "Hello World".
>>>>
>>>> Does anyone know the solution to this problem?
>>>>
>>>> Thank you very much in advance.
>>>>
>>>> Marion
>>>>
>>>>        [[alternative HTML version deleted]]
>>>>
>>>> ______________________________**________________
>>>> R-help at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>>> PLEASE do read the posting guide http://www.R-project.org/**
>>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>>
>>> --
>>> Dimitris Rizopoulos
>>> Assistant Professor
>>> Department of Biostatistics
>>> Erasmus University Medical Center
>>>
>>> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
>>> Tel: +31/(0)10/7043478
>>> Fax: +31/(0)10/7043014
>>> Web: http://www.erasmusmc.nl/**biostatistiek/<http://www.erasmusmc.nl/biostatistiek/>
>>>
>>
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 



More information about the R-help mailing list