[R] How to get all combinations between two character vectors?

2011-03-11 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi I know there is a function - I have used it before - but I always forget what it is called... I need the combination of two character vectors, i.e: x - c(a, b) y - c(x, y) z - THEFUNCTION(x, y) z == c(ax, ay, bx, by) I promise I will write

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread Dennis Murphy
Hi: This is probably not quite what you had in mind, but both work for your example - I think the second is probably easier. x - c(a, b) y - c(x, y) as.vector(outer(x, y, function(x, y) paste(x, y, sep = ''))) [1] ax bx ay by apply(expand.grid(x, y), 1, paste, collapse = '') [1] ax bx ay by

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 03/11/2011 12:22 PM, Dennis Murphy wrote: Hi: This is probably not quite what you had in mind, No - the second one is the one I used before. Thanks, Rainer but both work for your example - I think the second is probably easier. x -

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread Eik Vettorazzi
Hi Rainer, I don't know a function for literally substituting THEFUNCTION, but x - c(a, b) y - c(x, y) sort(levels(interaction(x,y,sep=))) or as.vector(t(outer(x,y,paste,sep=))) will work. sort and t respectively here are used to produce the desired order. hth. Am 11.03.2011 11:53, schrieb

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread Eik Vettorazzi
or even simpler paste(rep(x,each=length(y)),y,sep=) Am 11.03.2011 12:44, schrieb Eik Vettorazzi: Hi Rainer, I don't know a function for literally substituting THEFUNCTION, but x - c(a, b) y - c(x, y) sort(levels(interaction(x,y,sep=))) or as.vector(t(outer(x,y,paste,sep=))) will

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 03/11/2011 12:48 PM, Eik Vettorazzi wrote: or even simpler paste(rep(x,each=length(y)),y,sep=) I like that one - it makes perfect sense. I might wrap it into a function and use it. Am 11.03.2011 12:44, schrieb Eik Vettorazzi: Hi Rainer,

Re: [R] How to get all combinations between two character vectors?

2011-03-11 Thread David L Lorenz
Rainer, The are probably lots of ways, I'd use levels(interaction(c(a, b), c('x', 'y'), sep='')) Dave Hi I know there is a function - I have used it before - but I always forget what it is called... I need the combination of two character vectors, i.e: x - c(a, b) y - c(x, y) z -