Always good to have that fourth way, just in case ....

> (Array3 <- as.vector(outer(Array2[-1], Array1, FUN=function(x, y) paste(y, 
> Array2[1], x, sep="."))))
[1] "height.trt0.trt1" "height.trt0.trt2" "weight.trt0.trt1" "weight.trt0.trt2" 
"age.trt0.trt1"    "age.trt0.trt2"
[7] "sex.trt0.trt1"    "sex.trt0.trt2"

HTH,
David L. Reiner
XR Trading LLC

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Maas James Dr (MED)
Sent: Tuesday, August 31, 2010 8:17 AM
To: r-help@r-project.org
Subject: [R] pasting together 2 character arrays

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"

I'm trying combinations of the "combinations" and "paste" functions, but no 
luck yet!
Any suggestions about most efficient approach most welcome.
Thanks

Jim

===============================
Dr. Jim Maas
University of East Anglia


        [[alternative HTML version deleted]]

______________________________________________
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.


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, "XR Content") are confidential 
and proprietary to XR Trading, LLC ("XR") and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

______________________________________________
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