Hi,
Look at ?combn
t(combn(Vector, 2))
gives:
[,1] [,2]
[1,] "a" "b"
[2,] "a" "c"
[3,] "b" "c"
No idea how it is speed-wise.
HTH,
Josh
On Fri, Jul 22, 2011 at 10:09 AM, Megh Dal <megh700004 at yahoo.com>
wrote:> Let say, I have a character vector of arbitrary length:
>
> Vector <- c("a", "b", "c")
>
> Using that vector I would like to create a matrix (with number of columns
as 2) with all pairwise combinations of those elements, like:
>
> Vector <- c("a", "b", "c")
> Mat ? ? <- rbind(c("a", "b"), c("a",
"c"), c("b", "c")); Mat ?# number of rows will
obviously be n(n-1)/2
> ? ? ?[,1] [,2]
> [1,] "a" ?"b"
> [2,] "a" ?"c"
> [3,] "b" ?"c"
>
>
> Order must be kept same as?c("c", "a") or
c("c", "b")?would not be allowed. Additionally, actually I
have a very big initial character vector therefore I need to maintain speed as
well.
>
> I would be really?grateful?if somebody guide me how to do that
>
> ______________________________________________
> 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/