2017-07-11 27 views
1

リストの各エンティティ内に複数の列を持つリストがあります。私はエンティティと同じ数の行を持つ別のデータフレームでこれをcbind()したいので、2つの列を抽出して各エンティティを1つの行に変換する必要があります。ここで複数の列を含むリストをデータフレームに変換する

は私のリストです:

[[1]] 
               spotify              href      id 
1 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
2 https://open.spotify.com/artist/2cy1zPcrFcXAJTP0APWewL https://api.spotify.com/v1/artists/2cy1zPcrFcXAJTP0APWewL 2cy1zPcrFcXAJTP0APWewL 
      name type         uri 
1  Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 
2 Gente De Zona artist spotify:artist:2cy1zPcrFcXAJTP0APWewL 


[[2]] 
               spotify              href      id 
1 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
2 https://open.spotify.com/artist/1noWnd8QFQD9VLxWEeo4Zf https://api.spotify.com/v1/artists/1noWnd8QFQD9VLxWEeo4Zf 1noWnd8QFQD9VLxWEeo4Zf 
     name type         uri 
1  Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 
2 Don Miguelo artist spotify:artist:1noWnd8QFQD9VLxWEeo4Zf 

[[3]] 
               spotify              href      id 
1 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
2 https://open.spotify.com/artist/7iJrDbKM5fEkGdm5kpjFzS https://api.spotify.com/v1/artists/7iJrDbKM5fEkGdm5kpjFzS 7iJrDbKM5fEkGdm5kpjFzS 
3 https://open.spotify.com/artist/37G8DfNgO4mQ3PKh5droSo https://api.spotify.com/v1/artists/37G8DfNgO4mQ3PKh5droSo 37G8DfNgO4mQ3PKh5droSo 
        name type         uri 
1    Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 
2    Sensato artist spotify:artist:7iJrDbKM5fEkGdm5kpjFzS 
3 Osmani Garcia "La Voz" artist spotify:artist:37G8DfNgO4mQ3PKh5droSo 

[[4]] 
               spotify              href      id 
1 https://open.spotify.com/artist/2cy1zPcrFcXAJTP0APWewL https://api.spotify.com/v1/artists/2cy1zPcrFcXAJTP0APWewL 2cy1zPcrFcXAJTP0APWewL 
2 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
      name type         uri 
1 Gente De Zona artist spotify:artist:2cy1zPcrFcXAJTP0APWewL 
2  Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 

[[5]] 
               spotify              href      id 
1 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
2 https://open.spotify.com/artist/5fjXwEPUkg5ucxmw4TpurV https://api.spotify.com/v1/artists/5fjXwEPUkg5ucxmw4TpurV 5fjXwEPUkg5ucxmw4TpurV 
    name type         uri 
1 Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 
2 Micha artist spotify:artist:5fjXwEPUkg5ucxmw4TpurV 

[[6]] 
               spotify              href      id 
1 https://open.spotify.com/artist/0TnOYISbd1XYRBk9myaseg https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg 0TnOYISbd1XYRBk9myaseg 
2 https://open.spotify.com/artist/7wU2WGCJ8HxkekHHE2QLul https://api.spotify.com/v1/artists/7wU2WGCJ8HxkekHHE2QLul 7wU2WGCJ8HxkekHHE2QLul 
    name type         uri 
1 Pitbull artist spotify:artist:0TnOYISbd1XYRBk9myaseg 
2 Fuego artist spotify:artist:7wU2WGCJ8HxkekHHE2QLul 

だから私は基本的に、リスト内の各エンティティで3番目と4番目の列を呼び出し、データフレームで出力を持っていると思います。行の数はリストの各エンティティごとに異なるため、idnameの2つの列を持つ新しいデータフレームで、各エンティティを独自の行に結合したいと考えています。

の目標は、このような最終的な出力の外観を持つことです。

          id       name 
0TnOYISbd1XYRBk9myaseg, 2cy1zPcrFcXAJTP0APWewL  Pitbull, Gente De Zona 
0TnOYISbd1XYRBk9myaseg, 1noWnd8QFQD9VLxWEeo4Zf   Pitbull, Don Miguelo 
0TnOYISbd1XYRBk9myaseg, 7iJrDbKM5fEkGdm5kpjFzS, 37G8DfNgO4mQ3PKh5droSo Pitbull, Sensato, Osmani Garcia "La Voz" 
2cy1zPcrFcXAJTP0APWewL, 0TnOYISbd1XYRBk9myaseg  Gente De Zona, Pitbull 
0TnOYISbd1XYRBk9myaseg, 5fjXwEPUkg5ucxmw4TpurV    Pitbull, Micha 
0TnOYISbd1XYRBk9myaseg, 7wU2WGCJ8HxkekHHE2QLul    Pitbull, Fuego 
+2

試し 'do.call(rbind、lapply(LST、機能をループすることができます(x)x [、2:3])) '' lst'があなたのリストである – Val

答えて

1

我々はlapply

list
do.call(rbind, lapply(lst, function(x) do.call(cbind, lapply(x[c('id', 'name')], toString)))) 
+1

素晴らしい、ありがとう –

関連する問題