I have a list of data frames that looks likes this:
dflist:
[[12]]
label site
<chr> <int>
[1] NODE_0000138 12
[2] NODE_0000222 12
[3] NODE_0000205 12
[4] NODE_0000241 12
[5] 061D03KR01 12
[6] 061D03KR03 12
[[15]]
label site
<chr> <int>
[1] NODE_0000203 15
[2] 061D03OR17 15
[3] 061D03OR19 15
[4] 061D03UR28 15
[[18]]
label site
<chr> <int>
[1] NODE_0000181 18
[2] NODE_0000226 18
[3] 061D03KR11 18
[4] 061D03OR02 18
[5] 061D03OR32 18`
I also have a data.frame with information:
df
from to
1 12 18
2 12 35
3 15 18
I have been trying ways to create a new data.frame so that values are repeated according to the df rows.
The df 1st row is
from to
1 12 18
So, I would like to obtain all possible combinations from the listdf with 12 and 18:
NODE_0000138 12 NODE_0000181 18
NODE_0000138 12 NODE_0000226 18
NODE_0000138 12 061D03KR11 18
NODE_0000138 12 061D03OR02 18
NODE_0000138 12 061D03OR32 18
NODE_0000222 12 NODE_0000181 18
NODE_0000222 12 NODE_0000226 18
NODE_0000222 12 061D03KR11 18
NODE_0000222 12 061D03OR02 18
NODE_0000222 12 061D03OR32 18
NODE_0000205 12 NODE_0000181 18
NODE_0000205 12 NODE_0000226 18
NODE_0000205 12 061D03KR11 18
NODE_0000205 12 061D03OR02 18
NODE_0000205 12 061D03OR32 18`
…
…
And so on, for all of the df rows. I though about a for loop, but it gets messy. Any other ideas??
Thanks!!!
I have also been playing with rep, rep_along, but I can’t get it to repeat the amount of times I need it to.
I have also tried c(rep(data.frame(c(dflist[[1]][1],dflist[[1]][2])), nrow(dflist[[1]]))) just to see if I could get it repeated, but something is missing.
Andrea R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.