Hi,
I will try to explain as clearly as possible:
I have got a dataframe with a following col names:
"P18" "P19" "P20" "P21" "P22" "P23" "P35" "P36" "P37" "P38" "P39" "P40" "P41".
With that code:
res <- expand_grid(set1 = paste0("P", 18:23),
set2 = paste0("P", 35:41))
it gives me this:
These values are at the same time col names in my dataframe:
I would like to test correlation between variables P18:P23 and P35:P41.
I would like to make a dataframe probably maybe with expand.grid similar to df on my first picture but with two additional columns indicating col numbers in order to see which col is paired with which regarding my original dataframe ?
Any ideas would be greatly appreciated, thank you.
dfM <- structure(list(P18 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 0, 1, 1), P19 = c(1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1,
1, 0, 0, 1, 0, 0, 1, 0, 1), P20 = c(1, 0, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1), P21 = c(1, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1), P22 = c(1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1), P23 = c(0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0), P35 = c(1,
1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1), P36 = c(0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0), P37 = c(0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0), P38 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), P39 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0), P40 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), P41 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), class = c("data.table",
"data.frame"), row.names = c(NA, -20L))