On Aug 31, 2010, at 9:16 AM, Maas James Dr (MED) wrote:

If possible I would like to combine two different character arrays in combinations

Array1 <- c("height","weight","age","sex")

Array2 <- c("trt0","trt1","trt2")

I would like to combine these two character vectors to end up with such ...

Array3

"height.trt0.trt1"
"height.trt0.trt2"
"weight.trt0.trt1"
"weight.trt0.trt2"
"age.trt0.trt1"
"age.trt0.trt2"
"sex.trt0.trt1"
"sex.trt0.trt2"


?expand.grid # and noting that "trt0" is handled differently than Array2[2:3]

> paste(expand.grid(Array1, Array2[2:3])[,1], Array2[1], expand.grid(Array1, Array2[2:3])[,2], sep=".") [1] "height.trt0.trt1" "weight.trt0.trt1" "age.trt0.trt1" "sex.trt0.trt1" "height.trt0.trt2"
[6] "weight.trt0.trt2" "age.trt0.trt2"    "sex.trt0.trt2"

--
David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to