我有一個數據幀df
,看起來像下面這樣:重塑長寬反覆行
Label Info 1 0-22 Records N/A 2 0-22 Records Poland 3 0-22 Records N/A 4 0-22 Records active 5 0-22 Records Hardcore 6 0-22 Records N/A 7 0-22 Records N/A 8 Nuclear Blast "Oeschstr. 40 73072 Donzdorf" 9 Nuclear Blast Germany 10 Nuclear Blast +49 7162 9280-0 11 Nuclear Blast active 12 Nuclear Blast Hardcore (early), Metal and subgenres 13 Nuclear Blast 1987 14 Nuclear Blast "Anstalt Records, Arctic Serenades, Cannibalised Serial Killer, Deathwish Office, Epica, Gore Records, Grind Syndicate Media, Mind Control Records, Nuclear Blast America, Nuclear Blast Brasil, Nuclear Blast Entertainment, Radiation Records, Revolution Entertainment" 15 Nuclear Blast Yes
我想重塑的廣泛哪裏df
看起來像:
Label Address Country Phone Status Genre Year Sub Online
1 0-22 Records N/A Poland N/A active Hardcore N/A N/A N/A
2 Nuclear Blast "Oes.." Germany +49...
.
.
重複行的數量從7到9不等,我使用reshape
和reshape2
,將鍵分配給「標籤」到n ovail。
編輯:dput
:
structure(list(label = c("0-22 Records", "0-22 Records", "0-22 Records",
"0-22 Records", "0-22 Records", "0-22 Records", "0-22 Records",
"Nuclear Blast", "Nuclear Blast", "Nuclear Blast", "Nuclear Blast",
"Nuclear Blast", "Nuclear Blast", "Nuclear Blast", "Nuclear Blast",
"Metal Blade Records", "Metal Blade Records", "Metal Blade Records",
"Metal Blade Records", "Metal Blade Records"), info = c(" N/A ",
"Poland", " N/A ", "active", " Hardcore ", " N/A ", "N/A", " Oeschstr.
40\r\n73072 Donzdorf ",
"Germany", " +49 7162 9280-0 ", "active", " Hardcore (early), Metal and
subgenres ", " 1987 ", "\n\t\t\t\t\t\t\t\t\tAnstalt
Records,\t\t\t\t\t\t\t\t\tArctic Serenades,\t\t\t\t\t\t\t\t\tCannibalised
Serial Killer,\t\t\t\t\t\t\t\t\tDeathwish
Office,\t\t\t\t\t\t\t\t\tEpica,\t\t\t\t\t\t\t\t\tGore
Records,\t\t\t\t\t\t\t\t\tGrind Syndicate Media,\t\t\t\t\t\t\t\t\tMind
Control Records,\t\t\t\t\t\t\t\t\tNuclear Blast
America,\t\t\t\t\t\t\t\t\tNuclear Blast Brasil,\t\t\t\t\t\t\t\t\tNuclear
Blast Entertainment,\t\t\t\t\t\t\t\t\tRadiation
Records,\t\t\t\t\t\t\t\t\tRevolution Entertainment\t\t\t\t\t ",
"Yes", " 5737 Kanan Road #143\r\nAgoura Hills, California 91301 ",
"United States", " N/A ", "active", " Heavy Metal, Extreme Metal "
)), .Names = c("label", "info"), class = c("data.table", "data.frame"
), row.names = c(NA, -20L), .internal.selfref = <pointer: 0x10200db78>)
新的列名稱(例如,「地址」,「國家」等)不會出現在數據中。需要將它們添加爲新列以確保給定行的數據在重新塑形後以正確的列結束。有沒有一種方法可以確定哪些新列名與數據中的哪些行一起使用? – eipi10
它看起來像'0-22記錄'缺少'年份'信息。看看行數。 '0-22 Records'只有7行,而'Nuclear Blast'有8行。 – www
是的,我認爲這是OP的觀點(見問題的最後一行)。如果不是'Label'每個級別的可變行數,解決方案將很簡單。 – eipi10