Rainer M. Krug
2007-Oct-01 12:23 UTC
[R] Concatenating one character vector into one string
Hi I am sure this is simple - but how can I convert one charecter vector into one string? example: x <- c("This ", "is ", "one ", "sentence.") should become "This is one entence" Thanks Rainer -- NEW EMAIL ADDRESS AND ADDRESS: Rainer.Krug at uct.ac.za RKrug at sun.ac.za WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug email: Rainer.Krug at uct.ac.za Rainer at krugs.de
Wayne.W.Jones at shell.com
2007-Oct-01 12:32 UTC
[R] Concatenating one character vector into one string
x <- c("This ", "is ", "one ", "sentence.") paste(x,collapse="") -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On Behalf Of Rainer M. Krug Sent: 01 October 2007 13:23 To: r-help Subject: [R] Concatenating one character vector into one string Hi I am sure this is simple - but how can I convert one charecter vector into one string? example: x <- c("This ", "is ", "one ", "sentence.") should become "This is one entence" Thanks Rainer -- NEW EMAIL ADDRESS AND ADDRESS: Rainer.Krug at uct.ac.za RKrug at sun.ac.za WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug email: Rainer.Krug at uct.ac.za Rainer at krugs.de ______________________________________________ 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.
Rainer M. Krug
2007-Oct-01 12:33 UTC
[R] Concatenating one character vector into one string
Thanks a million Rainer Wayne.W.Jones at shell.com wrote:> x <- c("This ", "is ", "one ", "sentence.") > paste(x,collapse="") > > > > -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org]On Behalf Of Rainer M. Krug > Sent: 01 October 2007 13:23 > To: r-help > Subject: [R] Concatenating one character vector into one string > > > Hi > > I am sure this is simple - but how can I convert one charecter vector > into one string? > > example: > > x <- c("This ", "is ", "one ", "sentence.") > > should become > "This is one entence" > > Thanks > > Rainer >-- NEW EMAIL ADDRESS AND ADDRESS: Rainer.Krug at uct.ac.za RKrug at sun.ac.za WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug email: Rainer.Krug at uct.ac.za Rainer at krugs.de
> x <- c("This ", "is ", "one ", "sentence.") > paste(x, collapse='')[1] "This is one sentence." On 10/1/07, Rainer M. Krug <Rainer at krugs.de> wrote:> Hi > > I am sure this is simple - but how can I convert one charecter vector > into one string? > > example: > > x <- c("This ", "is ", "one ", "sentence.") > > should become > "This is one entence" > > Thanks > > Rainer > > -- > NEW EMAIL ADDRESS AND ADDRESS: > > Rainer.Krug at uct.ac.za > > RKrug at sun.ac.za WILL BE DISCONTINUED END OF MARCH > > Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation > Biology (UCT) > > Plant Conservation Unit > Department of Botany > University of Cape Town > Rondebosch 7701 > South Africa > > Tel: +27 - (0)21 650 5776 (w) > Fax: +27 - (0)86 516 2782 > Fax: +27 - (0)21 650 2440 (w) > Cell: +27 - (0)83 9479 042 > > Skype: RMkrug > > email: Rainer.Krug at uct.ac.za > Rainer at krugs.de > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Rainer, This works: paste(x, sep="", collapse="") I would have thought this 'paste(x) would work, but it didn't. Perhaps someone else can tell us why we need collapse="". What would break if the default was collapse="" instead of collapse=NULL? Thanks, Roger -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rainer M. Krug Sent: Monday, October 01, 2007 8:23 AM To: r-help Subject: [R] Concatenating one character vector into one string Hi I am sure this is simple - but how can I convert one charecter vector into one string? example: x <- c("This ", "is ", "one ", "sentence.") should become "This is one entence" Thanks Rainer -- NEW EMAIL ADDRESS AND ADDRESS: Rainer.Krug at uct.ac.za RKrug at sun.ac.za WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype: RMkrug email: Rainer.Krug at uct.ac.za Rainer at krugs.de ______________________________________________ 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. ********************************************************************** * This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No right to confidential or privileged treatment of this message is waived or lost by any error in transmission. If you have received this message in error, please immediately notify the sender by e-mail, delete the message and all copies from your system and destroy any hard copies. You must not, directly or indirectly, use, disclose, distribute, print or copy any part of this message if you are not the intended recipient.