[R] How to get all combinations between two character vectors?
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Fri Mar 11 12:44:40 CET 2011
Hi Rainer,
I don't know a function for literally substituting "THEFUNCTION", but
x <- c("a", "b")
y <- c("x", "y")
sort(levels(interaction(x,y,sep="")))
or
as.vector(t(outer(x,y,paste,sep="")))
will work. "sort" and "t" respectively here are used to produce the
desired order.
hth.
Am 11.03.2011 11:53, schrieb Rainer M Krug:
> Hi
>
> I know there is a function - I have used it before - but I always forget
> what it is called...
>
> I need the combination of two character vectors, i.e:
>
> x <- c("a", "b")
> y <- c("x", "y")
>
> z <- THEFUNCTION(x, y)
>
> z == c("ax", "ay", "bx", "by")
>
> I promise I will write the name of the function on my desk!
>
> Thanks,
>
> Rainer
>
______________________________________________
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.
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
More information about the R-help
mailing list