I have a list of dataframes, each with two columns. Columns have the same class and name in each dataframe and generally only differ in number of rows, e.g.,
lst = list(data.frame(n=1:3,
l=letters[seq(1:3)]),
data.frame(n=1:5,
l=letters[seq(1:5)]),
data.frame(n=1:8,
l=letters[seq(1:8)]))
I'm trying to create a new list of dataframes containing all possible pairwise combinations of values within each column (not between columns), but I haven't been able to get it right.
This code gives me the desired output for a single column, but I haven't been able to figure out how to apply it to all columns in all dataframes in the list using either lapply or for loops, though I'm sure there must be something I'm missing.
library(gtools)
library(tidyverse)
as.data.frame(combinations(nrow(lst[[1]]), 2, v=lst[[1]]$n, set=T, repeats.allowed=F)) %>%
transmute(x = paste(V1, V2, sep=","))
I'd really appreciate any tips!