I have two dataframes with 3 columns each and each dataframe consists of different data types (df1 has continuous data with column name suffix "con", df2 has categorical data with column name suffix "cat")
My data:
df1 <- data.frame(t1_con=c(1:5), t2_con=c(6:10), t3_con=c(11:15))
df2 <- data.frame(t1_cat=letters[1:5], t2_cat=letters[6:10], t3_cat=letters[11:15]))
I would like to get all combinations of the column names i.e. t1_con, t2_con, t3_cat I have tried this code:
df3 <- cbind(df1, df2)
results <- combn(names(df3),3,simplify=FALSE)
trait_combinations <- melt(results)
This gives me combinations like: t1_con, t2_con, t1_cat which has a duplicate of t1. But, I don't want any duplicates of t1, t2 or t3. E.g. group 1 is good, as there is t1, t2 and t3 within a group, but group 2 has a duplicate of t1:
head(trait_combinations)
value L1
1 t1_con 1
2 t2_con 1
3 t3_con 1
4 t1_con 2
5 t2_con 2
6 t1_cat 2
Is there a way to prevent duplicates from happening in combn, or to post-hoc remove duplicated strings? I could remove the suffixes but I need to know which columns are continuous and categorical for further analysis.
Thanks for your help.