I have a vector say:
vec = c("A", "B", "C")
And I want to paste single combinations of every item in the vector to get the result
AB
AC
BC
I know I can use outer to get all possible combinations of the vector, but I am stumped as how to only get the result above. Order doesn't matter in this case, so the result could plausibly also be
BA
CA
CB
I just need to combine the single pairs.
Sam
Try combn
combn(vec,2, FUN=paste, collapse='')
#[1] "AB" "AC" "BC"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With