Re: [R] concatenating two vectors

2012-09-14 Thread Berend Hasselman
On 14-09-2012, at 14:54, Özgür Asar wrote: > Dear all, > > I want to concatenate the elements of two vectors such as > > a<-c("a1","a2") > b<-c("b1","b2") > > and obtain > > "a1b1", "a1b2","a2b1","a2b2" > > I tried the paste and paste0 functions, but they yielded elementwise > concatenation

Re: [R] concatenating two vectors

2012-09-14 Thread arun
Hi, Try this:  paste0(expand.grid(a,b)$Var1,expand.grid(a,b)$Var2) [1] "a1b1" "a2b1" "a1b2" "a2b2" A.K. - Original Message - From: Özgür Asar To: r-help@r-project.org Cc: Sent: Friday, September 14, 2012 8:54 AM Subject: [R] concatenating two v

Re: [R] concatenating two vectors

2012-09-14 Thread R. Michael Weylandt
On Fri, Sep 14, 2012 at 1:54 PM, Özgür Asar wrote: > Dear all, > > I want to concatenate the elements of two vectors such as > > a<-c("a1","a2") > b<-c("b1","b2") > > and obtain > > "a1b1", "a1b2","a2b1","a2b2" > > I tried the paste and paste0 functions, but they yielded elementwise > concatenatio

Re: [R] concatenating two vectors

2012-09-14 Thread Jorge I Velez
Dear Ozgur, Try sort(apply(expand.grid(a, b), 1, paste0, collapse = "")) HTH, Jorge.- On Fri, Sep 14, 2012 at 8:54 AM, Özgür Asar <> wrote: > Dear all, > > I want to concatenate the elements of two vectors such as > > a<-c("a1","a2") > b<-c("b1","b2") > > and obtain > > "a1b1", "a1b2","a2b1"

[R] concatenating two vectors

2012-09-14 Thread Özgür Asar
Dear all, I want to concatenate the elements of two vectors such as a<-c("a1","a2") b<-c("b1","b2") and obtain "a1b1", "a1b2","a2b1","a2b2" I tried the paste and paste0 functions, but they yielded elementwise concatenation such as "a1b1","a2b2" I am wondering that is there an efficient way o

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Stavros Macrakis
If you want to concatenate the *vectors*, you need 'c', which will also coerce the elements to a common type. If you want to concatenate the corresponding *elements* of the vectors, you need 'paste', which will coerce them to character strings. -s On 5/18/09, Henning Wildhagen wrote:

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Simon Pickett
Sorry, I saw the word concatenate and dived in. Andrew Dolmans solution works fine. Simon. - Original Message - From: "Linlin Yan" To: "Simon Pickett" Cc: "Henning Wildhagen" ; Sent: Monday, May 18, 2009 12:30 PM Subject: Re: [R] Concatenating tw

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
ote: > z<-c(x,y) > > cheers, Simon. > > > - Original Message - From: "Henning Wildhagen" > To: > Sent: Monday, May 18, 2009 12:09 PM > Subject: [R] Concatenating two vectors into one > > >> Dear users, >> >> a very simple qu

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Uwe Ligges
Henning Wildhagen wrote: Dear users, a very simple question: Given two vectors x and y x<-as.character(c("A","B","C","D","E","F")) y<-as.factor(c("1","2","3","4","5","6")) i want to combine them into a single vector z as A1, B2, C3 and so on. z<-x*y is not working, i tried several others

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Linlin Yan
> z <- paste(x, y, sep = '') > z [1] "A1" "B2" "C3" "D4" "E5" "F6" On Mon, May 18, 2009 at 7:09 PM, Henning Wildhagen wrote: > Dear users, > > a very simple question: > > Given two vectors x and y > > x<-as.character(c("A","B","C","D","E","F")) > y<-as.factor(c("1","2","3","4","5","6")) > > i wan

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Ted Harding
On 18-May-09 11:09:45, Henning Wildhagen wrote: > Dear users, > a very simple question: > > Given two vectors x and y > > x<-as.character(c("A","B","C","D","E","F")) > y<-as.factor(c("1","2","3","4","5","6")) > > i want to combine them into a single vector z as A1, B2, C3 and so on. > > z<-x*

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Tony Breyal
Something like this should work: z<- paste(x,y, sep='') HTH, Tony On 18 May, 12:09, "Henning Wildhagen" wrote: > Dear users, > > a very simple question: > > Given two vectors x and y > > x<-as.character(c("A","B","C","D","E","F")) > y<-as.factor(c("1","2","3","4","5","6")) > > i want to combine

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Andrew Dolman
x<-as.character(c("A","B","C","D","E","F")) y<-as.factor(c("1","2","3","4","5","6")) ?paste paste(x,y, sep="") andydol...@gmail.com 2009/5/18 Henning Wildhagen > Dear users, > > a very simple question: > > Given two vectors x and y > > x<-as.character(c("A","B","C","D","E","F")) > y<-as.

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Simon Pickett
z<-c(x,y) cheers, Simon. - Original Message - From: "Henning Wildhagen" To: Sent: Monday, May 18, 2009 12:09 PM Subject: [R] Concatenating two vectors into one Dear users, a very simple question: Given two vectors x and y x<-as.character(c("A&quo

[R] Concatenating two vectors into one

2009-05-18 Thread Henning Wildhagen
Dear users, a very simple question: Given two vectors x and y x<-as.character(c("A","B","C","D","E","F")) y<-as.factor(c("1","2","3","4","5","6")) i want to combine them into a single vector z as A1, B2, C3 and so on. z<-x*y is not working, i tried several others function, but did not get to