HI,
Try this:
T1<- paste0("c",1:5)
?T2<- paste0("k",1:5)
? as.vector(outer(T1,T2,paste,sep=","))
# [1] "c1,k1" "c2,k1" "c3,k1" "c4,k1"
"c5,k1" "c1,k2" "c2,k2" "c3,k2"
"c4,k2"
#[10] "c5,k2" "c1,k3" "c2,k3" "c3,k3"
"c4,k3" "c5,k3" "c1,k4" "c2,k4"
"c3,k4"
#[19] "c4,k4" "c5,k4" "c1,k5" "c2,k5"
"c3,k5" "c4,k5" "c5,k5"
#or
?paste("(",as.vector(outer(T1,T2,paste,sep=",")),")",sep="")
?#[1] "(c1,k1)" "(c2,k1)" "(c3,k1)"
"(c4,k1)" "(c5,k1)" "(c1,k2)" "(c2,k2)"
?#[8] "(c3,k2)" "(c4,k2)" "(c5,k2)"
"(c1,k3)" "(c2,k3)" "(c3,k3)" "(c4,k3)"
#[15] "(c5,k3)" "(c1,k4)" "(c2,k4)"
"(c3,k4)" "(c4,k4)" "(c5,k4)" "(c1,k5)"
#[22] "(c2,k5)" "(c3,k5)" "(c4,k5)"
"(c5,k5)"
A.K.
----- Original Message -----
From: Amir <adarehsh at uottawa.ca>
To: r-help at r-project.org
Cc:
Sent: Friday, March 15, 2013 9:22 AM
Subject: [R] Combinations
Hi every one,
I have two sets T1={c1,c2,..,cn} and T2={k1,k2,...,kn}.
How can I find the sets as follow:
(c1,k1), (c1,k2) ...(c1,kn)? (c2,k1) (c2,k2) .... (c2,kn) ... (cn,kn)
Thanks.
Amir
-- __________________________________________________________________________
Amir Darehshoorzadeh? ? ? ? ? ? |? Computer Engineering Department
PostDoc Fellow? ? ? ? ? ? ? ? ? |? University of Ottawa, PARADISE LAb
Email: adarehsh at uottawa.ca? ? ? |? 800 King Edward Ave
Tel: -? ? ? ? ? ? ? ? ? ? ? ? ? |? ON K1N 6N5, Ottawa - CANADA
http://personals.ac.upc.edu/amir
______________________________________________
R-help at 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.