Re: [R] Combining characters

2012-01-04 Thread Justin Haynes
apply(expand.grid(x, y, z, stringsAsFactors=F), 1, paste, collapse=' ') On Wed, Jan 4, 2012 at 8:32 AM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("one","two","three") > y=c("yellow","blue","green") > z=c("apple","cheese") > > in or

Re: [R] Combining characters

2012-01-04 Thread Joshua Wiley
Try expand.grid() to create all the combinations. Then just collapse them with paste(): apply(expand.grid(x, y, z), 1, paste, collapse = " ") Cheers, Josh On Wed, Jan 4, 2012 at 8:32 AM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("

Re: [R] Combining characters

2012-01-04 Thread Marc Schwartz
On Jan 4, 2012, at 10:32 AM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("one","two","three") > y=c("yellow","blue","green") > z=c("apple","cheese") > > in order to get concatenation of > > x[1] y[1] z[1] ("one yellow apple") > x[1

Re: [R] Combining characters

2012-01-04 Thread R. Michael Weylandt
? expand.grid Michael On Wed, Jan 4, 2012 at 10:32 AM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("one","two","three") > y=c("yellow","blue","green") > z=c("apple","cheese") > > in order to get concatenation of > > x[1] y[1] z[1]  ("o

Re: [R] Combining characters

2012-01-04 Thread andrija djurovic
Hi. You can use expand.grid here expand.grid(x,y,z) Andrija On Wed, Jan 4, 2012 at 5:32 PM, jeremy wrote: > Hi all, > > I'm trying to combine exhaustively several character arrays in R like: > x=c("one","two","three") > y=c("yellow","blue","green") > z=c("apple","cheese") > > in order to get co

Re: [R] Combining characters

2012-01-04 Thread Rui Barradas
Hello, If you want to apply the same procedure to all elements of an object, check out the '*apply' functions. In this case, x=c("one","two","three") y=c("yellow","blue","green") z=c("apple","cheese") lapply(x, function(x) paste(x, y)) gives a good picture of what you want to do, just transfo

[R] Combining characters

2012-01-04 Thread jeremy
Hi all, I'm trying to combine exhaustively several character arrays in R like: x=c("one","two","three") y=c("yellow","blue","green") z=c("apple","cheese") in order to get concatenation of x[1] y[1] z[1] ("one yellow apple") x[1] y[1] z[2] ("one yellow cheese") x[1] y[2] z[1]("one blue apple")