Hello! s<-"start"; e<-"end" middle<-as.character(c(1,2,3)) I would like to get the following result: "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" How can I avoide this (undesired) result: paste(s,middle,e,sep=" ") Thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com
paste(s,paste(middle,collapse=""),e,collapse=" ") On Fri, Feb 25, 2011 at 4:21 PM, Dimitri Liakhovitski < dimitri.liakhovitski@gmail.com> wrote:> Hello! > > s<-"start"; e<-"end" > middle<-as.character(c(1,2,3)) > > I would like to get the following result: > "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" > > How can I avoide this (undesired) result: > paste(s,middle,e,sep=" ") > > > Thank you! > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
The easiest thing to do is add a second paste statement:> paste(s, paste(middle, collapse=" "), e, sep=" ")[1] "start 1 2 3 end"> paste(s, paste(middle, collapse=","), e, sep=" ")[1] "start 1,2,3 end"> paste(s, paste(middle, collapse=", "), e, sep=" ")[1] "start 1, 2, 3 end" On Fri, Feb 25, 2011 at 5:21 PM, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:> Hello! > > s<-"start"; e<-"end" > middle<-as.character(c(1,2,3)) > > I would like to get the following result: > "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" > > How can I avoide this (undesired) result: > paste(s,middle,e,sep=" ") > > > Thank you! > ---- Sarah Goslee http://www.functionaldiversity.org
Hi Dimitri, You can do it like this: paste(s,paste(middle, collapse=""),e,sep=" ") Best, Ista On Fri, Feb 25, 2011 at 5:21 PM, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:> Hello! > > s<-"start"; e<-"end" > middle<-as.character(c(1,2,3)) > > I would like to get the following result: > "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" > > How can I avoide this (undesired) result: > paste(s,middle,e,sep=" ") > > > Thank you! > -- > Dimitri Liakhovitski > Ninah Consulting > www.ninah.com > > ______________________________________________ > 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. >-- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org
> s<-"start"; e<-"end" > middle<-as.character(c(1,2,3)) > > I would like to get the following result: > "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" > > How can I avoide this (undesired) result: > paste(s,middle,e,sep=" ")Sometimes you just have to do something more than once: paste(s, paste(middle, collapse=','), e, sep=" ") cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.curt@epa.gov 541/754-4638 [[alternative HTML version deleted]]
On Fri, Feb 25, 2011 at 5:21 PM, Dimitri Liakhovitski <dimitri.liakhovitski at gmail.com> wrote:> Hello! > > s<-"start"; e<-"end" > middle<-as.character(c(1,2,3)) > > I would like to get the following result: > "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" > > How can I avoide this (undesired) result: > paste(s,middle,e,sep=" ")Try this:> paste(s, toString(middle), e)[1] "start 1, 2, 3 end" -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
This is great, thanks a lot, Gabor! On Fri, Feb 25, 2011 at 6:18 PM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:> On Fri, Feb 25, 2011 at 5:21 PM, Dimitri Liakhovitski > <dimitri.liakhovitski at gmail.com> wrote: >> Hello! >> >> s<-"start"; e<-"end" >> middle<-as.character(c(1,2,3)) >> >> I would like to get the following result: >> "start 123 end" or "start 1 2 3 end" or "start 1,2,3 end" >> >> How can I avoide this (undesired) result: >> paste(s,middle,e,sep=" ") > > Try this: > >> paste(s, toString(middle), e) > [1] "start 1, 2, 3 end" > > > > -- > Statistics & Software Consulting > GKX Group, GKX Associates Inc. > tel: 1-877-GKX-GROUP > email: ggrothendieck at gmail.com >-- Dimitri Liakhovitski Ninah Consulting www.ninah.com
Maybe Matching Threads
- finding the year of a date
- merging 2 frames while keeping all the entries from the "reference" frame
- any way to make it work faster (deleting rows that contain certain values)
- transforming a badly organized data base into a list of data frames
- Suppressing printing in the function