Lets say I have two vectors:
x <- c("A", "B")
y <- c("C")
I would then like to find and collect all combinations of x
and y
in the following manner:
DesiredOutput <- list(c('A', 'C'), c('B', 'C'))
I have tried using expand.grid
in combination with split
as follows:
xy.df <- expand.grid(x, y)
xy.list <- split(xy.df, 1:nrow(xy.df))
However, this does not produce the desired output as for instance xy.list[[1]][1]
is no longer a character. And if I try to simply do as.character(xy.list[[1]][1])
then this returns a "1"
. So, what can I do instead?