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
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
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
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"
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
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:
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
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
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
> 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
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*
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
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.
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
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
15 matches
Mail list logo