rom: Petr PIKAL [mailto:petr.pi...@precheza.cz]
Sent: 29 August 2011 07:24
To: Campbell, Desmond
Cc: r-help@R-project.org
Subject: Odp: [R] all combinations of the elements of two vectors
Hi
Dear R-help readers,
I'm sure this problem has been answered but I can't find the
solution.
I have t
t: Odp: [R] all combinations of the elements of two vectors
Hi
>
> Dear R-help readers,
>
> I'm sure this problem has been answered but I can't find the solution.
>
> I have two vectors
> v1 <- c("a","b")
> v2 <- c(1,2,3)
> I want an
11 19:19
To: Campbell, Desmond
Cc: r-help@R-project.org
Subject: Re: [R] all combinations of the elements of two vectors
Hi Desmond,
You might try
> sort(apply(expand.grid(v1, v2), 1, paste, collapse = "", sep = ""))
[1] "a1" "a2" "a3" &qu
x<-letters[1:3]
y<-1:3
d<-expand.grid(x,y)
g<-apply(d,1,function(x) paste(x[1],x[2],sep=""))
HTH,
Daniel
Campbell, Desmond-2 wrote:
>
> Dear R-help readers,
>
> I'm sure this problem has been answered but I can't find the solution.
>
> I have two vectors
> v1 <- c("a","b")
> v2 <- c(1,2,3)
Hi Desmond,
You might try
> sort(apply(expand.grid(v1, v2), 1, paste, collapse = "", sep = ""))
[1] "a1" "a2" "a3" "b1" "b2" "b3"
HTH,
Jorge
On Sat, Aug 27, 2011 at 12:54 PM, Campbell, Desmond <> wrote:
> Dear R-help readers,
>
> I'm sure this problem has been answered but I can't find the so
Dear R-help readers,
I'm sure this problem has been answered but I can't find the solution.
I have two vectors
v1 <- c("a","b")
v2 <- c(1,2,3)
I want an easy way to produce every possible combination of v1, v2 elements
Ie I want to produce
c("a1","a2","a3", "b1","b2","b3")
regards
Desmond
Desmo
6 matches
Mail list logo