I had a specific question about turning my data into two columns so I can make an edgelist. I've attached a screenshot of the data. There's up to V10, and each row represents artists that have worked on the same song. I wanted to create an edgelist with the artist names. For example, for rows that have person A, B, C, D, I wanted to create:
A B
A C
A D
B C
B D
C D
The code I used so far is:
reltest <- t(do.call(cbind, lapply(cleanartists[sapply(cleanartists, length) >= 2], combn, 2)))
But this gives me all possible combinations among the artist names, not just the ones that have existing relationships. This is what my data looks like:
> head(cleanartists, n = 20)
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1 Bethel Music Jenn Johnson <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
2 Gal Costa Caetano Veloso <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
3 JAYZ Kanye West <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
4 2Pac Danny Boy <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
5 Ludacris Shawnna <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
6 Richard Armitage The Dwarf Cast <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
7 Ludacris TPain <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
8 The Velvet Underground Lou Reed <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
9 The Stanley Brothers The Clinch Mountain Boys <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
10 The Carter Sisters Mother Maybelle <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
11 Lady Gaga Colby ODonis <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
12 Rihanna JAYZ <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
13 Lil Yachty Trippie Redd <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
14 Brian Tuey James McCawley Kevin Sherwood Treyarch Sound <NA> <NA> <NA> <NA> <NA> <NA>
15 Sister Rosetta Tharpe The Rosettes <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
16 Bing Crosby The Andrews Sisters <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
17 Stone Poneys Linda Ronstadt <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
18 J Cole Drake <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
19 The Last Shadow Puppets Alex Turner Miles Kane <NA> <NA> <NA> <NA> <NA> <NA> <NA>
20 Gal Costa Caetano Veloso <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>