Изменение формы нескольких столбцов с неупорядоченными значениями

#r #dataframe #reshape2

Вопрос:

У меня есть набор данных с несколькими столбцами, который я хочу изменить. По сути, данные из столбцов, соответствующих цифрам, становятся столбцами, получающими соответствующее значение в этой строке из столбцов v1:v12 .

Я пытался:

  tt2 lt;- melt(tt, id.vars=c(1:6, 12:16)) tt3 lt;- melt(tt2, id.vars=c(1:6, 12:13)) names(tt3)[7:10]lt;-c("content", "names", "data_value", "values") final_tt lt;- tt3 %gt;% pivot_wider(names_from = names, values_from = values)  

Однако данные получаются такими:

 # A tibble: 500 × 28  ...1 category name price product_url location content data_value `Character:` `Card Size:` `Game:` `Year Manufactu… `Language:` `Graded:`  lt;dblgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;fctgt; lt;fctgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;chrgt; lt;chrgt;   1 24 ultra_rare PSA … $1,6… https://ww… toyama,… one v1 Charizard NA NA NA NA NA   2 107 english Shin… $7,4… https://ww… Melbour… one v1 Charizard NA NA NA NA NA   3 166 legendary 84/1… £2.99 https://ww… Sheffie… one v1 Onix NA NA NA NA NA   4 172 ultra_rare PIKA… $1,0… https://ww… Tiverto… one v1 Pikachu NA NA NA NA NA   5 196 legendary 59/1… £1.99 https://ww… Sheffie… one v1 Primeape NA NA NA NA NA   6 202 legendary 70/1… £3.99 https://ww… Sheffie… one v1 Charmander NA NA NA NA NA   7 287 french Char… £15.… https://ww… Glossop… one v1 Charmander NA NA NA NA NA   8 502 used Shin… £2,4… https://ww… Melbour… one v1 Raichu NA NA NA NA NA   9 945 french Noeu… £1.50 https://ww… Enfield… one v1 Exeggcute NA NA NA NA NA  10 2087 french Noeu… £0.99 https://ww… Enfield… one v1 Exeggcute NA NA NA NA NA  # … with 490 more rows, and 14 more variables: Card Type: lt;chrgt;, Card Number: lt;chrgt;, Finish: lt;chrgt;, Features: lt;chrgt;, Material: lt;chrgt;, # Rarity: lt;chrgt;, Card Condition: lt;chrgt;, Manufacturer: lt;chrgt;, NA lt;chrgt;, Card Name: lt;chrgt;, Grade: lt;chrgt;, Pokid: lt;chrgt;,  

Я подумал, что, учитывая, что они находятся в одном ряду, то их соответствующие значения должны совпадать?

Воспроизводимый код:

 structure(list(...1 = c(24, 107, 166, 172, 196, 202, 287, 502,  945, 2087, 2156, 2722, 2725, 2740, 2744, 2774, 2808, 2979, 3012,  3195), category = c("ultra_rare", "english", "legendary", "ultra_rare",  "legendary", "legendary", "french", "used", "french", "french",  "french", "used", "used", "used", "used", "used", "used", "used",  "used", "used"), name = c("PSA 10 GEM MINT Pokemon Japanese Card 209/150 CHARIZARD GX 2018 Ultra Shiny SSR",  "Shining Charizard Holo Pokemon Card Unlimited Neo Destiny 107/105 BGS PSA 10 GEM",  "84/110 | Onix | Legendary | Pokemon Card | Near Mint", "PIKACHU 025 Vintage JAPANESE Jungle Set Pokemon Card -1996 Ultra Rare error Card",  "59/110 | Primeape | Legendary | Pokemon Card | Played", "70/110 | Charmander | Legendary | Pokemon Card | Near Mint",  "Charmander - 46/102 - Common - Base Set Unlimited Pokemon Card - French - NM",  "Shining Raichu Holo Pokemon Card 1st Edition Neo Destiny 111/105 BGS PSA 10",  "Noeufnoeuf (Exeggcute) 52/64 Jungle French Extremely rare Pokemon Card good cond",  "Noeufnoeuf (Exeggcute) 52/64 Jungle French Extremely rare Pokemon Card good cond",  "2013 - Pokemon Card URSARING- PV 130 - Level 1 - 76 / 101- French -N ° 217- TB",  "Venusaur Holo Pokemon Card 2002 Expedition 6/165 BGS PSA 10 Gem Mint",  "MINT Squirtle First Edition Stamp Shadowless Pokemon Card 63/102 100% Genuine",  "MINT Bulbasaur First Edition Stamp Shadowless Pokemon Card 44/102",  "Charizard Holo Pokemon Card 1999 Original Base Set 4/102 ARK PSA BGS 9 9.5/9/9/9",  "MINT Charmander First Edition Stamp Shadowless Pokemon Card 46/102 100% Genuine",  "Entei Gold Star Holo Pokemon Card EX Unseen Forces 113/115 BGS PSA 10 GEM MINT",  "Charizard 2nd Edition Pokemon Card Holo", "Pokemon Cards Japanese TCG Team Rocket joins! Oid-back PSA10",  "Pokemon Cards Japanese TCG Pikachu Battle Festa 2014 Promo 090/XY-P PSA10" ), price = c("$1,650.00", "$7,441.48", "£2.99", "$1,000.00",  "£1.99", "£3.99", "£15.00", "£2,409.05", "£1.50", "£0.99",  "£4.79", "£1,444.36", "£1,500.00", "£1,500.00", "£1,551.55",  "£1,500.00", "£1,176.39", "£1,200.00", "£1,122.00", "£1,059.00" ), location = c("toyama, Japan", "Melbourne, Australia", "Sheffield, United Kingdom",  "Tiverton, Rhode Island, United States", "Sheffield, United Kingdom",  "Sheffield, United Kingdom", "Glossop, United Kingdom", "Melbourne, Australia",  "Enfield, United Kingdom", "Enfield, United Kingdom", "Paris, France",  "Melbourne, Australia", "Newton Aycliffe, United Kingdom", "Newton Aycliffe, United Kingdom",  "Melbourne, Australia", "Newton Aycliffe, United Kingdom", "Melbourne, Australia",  "Hove, United Kingdom", "higasiosaksioohasuhigasi, Japan", "higasiosaksioohasuhigasi, Japan" ), one = c("Character:", "Character:", "Character:", "Character:",  "Character:", "Character:", "Character:", "Character:", "Character:",  "Character:", "Character:", "Character:", "Character:", "Character:",  "Character:", "Character:", "Character:", "Character:", "Character:",  "Character:"), two = c("Card Size:", "Card Size:", "Game:", "Year Manufactured:",  "Game:", "Game:", "Language:", "Graded:", "Card Type:", "Card Type:",  "Card Number:", "Finish:", "Features:", "Features:", "Card Size:",  "Features:", "Material:", "Card Type:", "Card Size:", "Card Size:" ), three = c("Card Number:", "Material:", "Card Number:", "Game:",  "Card Number:", "Card Number:", "Game:", "Year Manufactured:",  "Rarity:", "Rarity:", "Card Condition:", "Manufacturer:", NA,  NA, "Material:", NA, "Year Manufactured:", "Game:", "Card Condition:",  "Card Name:"), four = c("Card Condition:", "Grade:", "Pokid:",  NA, "Pokid:", "Pokid:", NA, "Card Type:", NA, NA, "Creature/Monster Type:",  "Card Size:", NA, NA, "Features:", NA, "Card Type:", NA, "Grade:",  "Graded:"), five = c("Creature/Monster Type:", "Year Manufactured:",  NA, NA, NA, NA, NA, "Finish:", NA, NA, "Card Type:", "Language:",  NA, NA, "Vintage:", NA, "Finish:", NA, "Vintage:", "Features:" ), v1 = c("Charizard", "Charizard", "Onix", "Pikachu", "Primeape",  "Charmander", "Charmander", "Raichu", "Exeggcute", "Exeggcute",  "Ursaring", "Venusaur", "Charmander", "Charmander", "Charizard",  "Charmander", "Entei", "Charizard", "Team Rocket j", "Pikachu" ), v2 = c("Standard", "Standard", "Pokémon TCG", "1996", "Pokémon TCG",  "Pokémon TCG", "French", "Yes", "Pokémon", "Pokémon", "217",  "Holo", "Shadowless", "Shadowless", "Standard", "Shadowless",  "Card Stock", "Pokémon", "Standard", "Standard"), v3 = c("209/150",  "Card Stock", "84/110", "Pokémon TCG", "59/110", "70/110", "Pokémon TCG",  "2002", "Rare", "Rare", "Light Play", "Pokemon", NA, NA, "Card Stock",  NA, "2005", "Pokémon TCG", "Near Mint", "Pikachu Battle Festa" ), v4 = c("Near Mint", "10", "5455", NA, "5430", "5441", NA,  "Pokémon", NA, NA, "Adrenarush", "Standard", NA, NA, "Holo",  NA, "Pokémon", NA, "10", "Yes"), v5 = c("Dragon", "2002", NA,  NA, NA, NA, NA, "Holo", NA, NA, "Team Plasma", "English", NA,  NA, "Yes", NA, "Holo", NA, "Yes", "Promo")), row.names = c(NA,  -20L), class = c("tbl_df", "tbl", "data.frame"))  

Комментарии:

1. Пожалуйста, приведите пример выходных данных, которые вам нужны.