Q1 Dataset Super Heróis da Kaggle. Importanto os arquivos para o R, concatenando para “hero_powers” e “hero_info”.

# Importanto dados heros power e heros informe
library(readr)
hero_powers <- read_csv(file = "/home/zarzar/Documentos/UFLA Doutorado/Disciplina/Data Science/Arquivo prof/Aula_dia_25/super_hero_powers.csv",na=c("","-","NA"))
## Parsed with column specification:
## cols(
##   .default = col_logical(),
##   hero_names = col_character()
## )
## See spec(...) for full column specifications.
hero_info <- read_csv(file = "/home/zarzar/Documentos/UFLA Doutorado/Disciplina/Data Science/Arquivo prof/Aula_dia_25/heroes_information.csv",
                        na=c("","-","NA"))
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
##   X1 = col_double(),
##   name = col_character(),
##   Gender = col_character(),
##   `Eye color` = col_character(),
##   Race = col_character(),
##   `Hair color` = col_character(),
##   Height = col_double(),
##   Publisher = col_character(),
##   `Skin color` = col_character(),
##   Alignment = col_character(),
##   Weight = col_double()
## )
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
# glimpse(hero_powers)
# glimpse(hero_info)

Q2 Usando a função janitor::clean_names() para limpar os nomes das colunas.

# install.packages("janitor")
library(janitor)
## 
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
names(hero_powers)
##   [1] "hero_names"                   "Agility"                     
##   [3] "Accelerated Healing"          "Lantern Power Ring"          
##   [5] "Dimensional Awareness"        "Cold Resistance"             
##   [7] "Durability"                   "Stealth"                     
##   [9] "Energy Absorption"            "Flight"                      
##  [11] "Danger Sense"                 "Underwater breathing"        
##  [13] "Marksmanship"                 "Weapons Master"              
##  [15] "Power Augmentation"           "Animal Attributes"           
##  [17] "Longevity"                    "Intelligence"                
##  [19] "Super Strength"               "Cryokinesis"                 
##  [21] "Telepathy"                    "Energy Armor"                
##  [23] "Energy Blasts"                "Duplication"                 
##  [25] "Size Changing"                "Density Control"             
##  [27] "Stamina"                      "Astral Travel"               
##  [29] "Audio Control"                "Dexterity"                   
##  [31] "Omnitrix"                     "Super Speed"                 
##  [33] "Possession"                   "Animal Oriented Powers"      
##  [35] "Weapon-based Powers"          "Electrokinesis"              
##  [37] "Darkforce Manipulation"       "Death Touch"                 
##  [39] "Teleportation"                "Enhanced Senses"             
##  [41] "Telekinesis"                  "Energy Beams"                
##  [43] "Magic"                        "Hyperkinesis"                
##  [45] "Jump"                         "Clairvoyance"                
##  [47] "Dimensional Travel"           "Power Sense"                 
##  [49] "Shapeshifting"                "Peak Human Condition"        
##  [51] "Immortality"                  "Camouflage"                  
##  [53] "Element Control"              "Phasing"                     
##  [55] "Astral Projection"            "Electrical Transport"        
##  [57] "Fire Control"                 "Projection"                  
##  [59] "Summoning"                    "Enhanced Memory"             
##  [61] "Reflexes"                     "Invulnerability"             
##  [63] "Energy Constructs"            "Force Fields"                
##  [65] "Self-Sustenance"              "Anti-Gravity"                
##  [67] "Empathy"                      "Power Nullifier"             
##  [69] "Radiation Control"            "Psionic Powers"              
##  [71] "Elasticity"                   "Substance Secretion"         
##  [73] "Elemental Transmogrification" "Technopath/Cyberpath"        
##  [75] "Photographic Reflexes"        "Seismic Power"               
##  [77] "Animation"                    "Precognition"                
##  [79] "Mind Control"                 "Fire Resistance"             
##  [81] "Power Absorption"             "Enhanced Hearing"            
##  [83] "Nova Force"                   "Insanity"                    
##  [85] "Hypnokinesis"                 "Animal Control"              
##  [87] "Natural Armor"                "Intangibility"               
##  [89] "Enhanced Sight"               "Molecular Manipulation"      
##  [91] "Heat Generation"              "Adaptation"                  
##  [93] "Gliding"                      "Power Suit"                  
##  [95] "Mind Blast"                   "Probability Manipulation"    
##  [97] "Gravity Control"              "Regeneration"                
##  [99] "Light Control"                "Echolocation"                
## [101] "Levitation"                   "Toxin and Disease Control"   
## [103] "Banish"                       "Energy Manipulation"         
## [105] "Heat Resistance"              "Natural Weapons"             
## [107] "Time Travel"                  "Enhanced Smell"              
## [109] "Illusions"                    "Thirstokinesis"              
## [111] "Hair Manipulation"            "Illumination"                
## [113] "Omnipotent"                   "Cloaking"                    
## [115] "Changing Armor"               "Power Cosmic"                
## [117] "Biokinesis"                   "Water Control"               
## [119] "Radiation Immunity"           "Vision - Telescopic"         
## [121] "Toxin and Disease Resistance" "Spatial Awareness"           
## [123] "Energy Resistance"            "Telepathy Resistance"        
## [125] "Molecular Combustion"         "Omnilingualism"              
## [127] "Portal Creation"              "Magnetism"                   
## [129] "Mind Control Resistance"      "Plant Control"               
## [131] "Sonar"                        "Sonic Scream"                
## [133] "Time Manipulation"            "Enhanced Touch"              
## [135] "Magic Resistance"             "Invisibility"                
## [137] "Sub-Mariner"                  "Radiation Absorption"        
## [139] "Intuitive aptitude"           "Vision - Microscopic"        
## [141] "Melting"                      "Wind Control"                
## [143] "Super Breath"                 "Wallcrawling"                
## [145] "Vision - Night"               "Vision - Infrared"           
## [147] "Grim Reaping"                 "Matter Absorption"           
## [149] "The Force"                    "Resurrection"                
## [151] "Terrakinesis"                 "Vision - Heat"               
## [153] "Vitakinesis"                  "Radar Sense"                 
## [155] "Qwardian Power Ring"          "Weather Control"             
## [157] "Vision - X-Ray"               "Vision - Thermal"            
## [159] "Web Creation"                 "Reality Warping"             
## [161] "Odin Force"                   "Symbiote Costume"            
## [163] "Speed Force"                  "Phoenix Force"               
## [165] "Molecular Dissipation"        "Vision - Cryo"               
## [167] "Omnipresent"                  "Omniscient"
names(hero_info)
##  [1] "X1"         "name"       "Gender"     "Eye color"  "Race"      
##  [6] "Hair color" "Height"     "Publisher"  "Skin color" "Alignment" 
## [11] "Weight"
(hero_powers <- clean_names(hero_powers))
## # A tibble: 667 x 168
##    hero_names agility accelerated_hea… lantern_power_r… dimensional_awa…
##    <chr>      <lgl>   <lgl>            <lgl>            <lgl>           
##  1 3-D Man    TRUE    FALSE            FALSE            FALSE           
##  2 A-Bomb     FALSE   TRUE             FALSE            FALSE           
##  3 Abe Sapien TRUE    TRUE             FALSE            FALSE           
##  4 Abin Sur   FALSE   FALSE            TRUE             FALSE           
##  5 Abominati… FALSE   TRUE             FALSE            FALSE           
##  6 Abraxas    FALSE   FALSE            FALSE            TRUE            
##  7 Absorbing… FALSE   FALSE            FALSE            FALSE           
##  8 Adam Monr… FALSE   TRUE             FALSE            FALSE           
##  9 Adam Stra… FALSE   FALSE            FALSE            FALSE           
## 10 Agent Bob  FALSE   FALSE            FALSE            FALSE           
## # … with 657 more rows, and 163 more variables: cold_resistance <lgl>,
## #   durability <lgl>, stealth <lgl>, energy_absorption <lgl>,
## #   flight <lgl>, danger_sense <lgl>, underwater_breathing <lgl>,
## #   marksmanship <lgl>, weapons_master <lgl>, power_augmentation <lgl>,
## #   animal_attributes <lgl>, longevity <lgl>, intelligence <lgl>,
## #   super_strength <lgl>, cryokinesis <lgl>, telepathy <lgl>,
## #   energy_armor <lgl>, energy_blasts <lgl>, duplication <lgl>,
## #   size_changing <lgl>, density_control <lgl>, stamina <lgl>,
## #   astral_travel <lgl>, audio_control <lgl>, dexterity <lgl>,
## #   omnitrix <lgl>, super_speed <lgl>, possession <lgl>,
## #   animal_oriented_powers <lgl>, weapon_based_powers <lgl>,
## #   electrokinesis <lgl>, darkforce_manipulation <lgl>, death_touch <lgl>,
## #   teleportation <lgl>, enhanced_senses <lgl>, telekinesis <lgl>,
## #   energy_beams <lgl>, magic <lgl>, hyperkinesis <lgl>, jump <lgl>,
## #   clairvoyance <lgl>, dimensional_travel <lgl>, power_sense <lgl>,
## #   shapeshifting <lgl>, peak_human_condition <lgl>, immortality <lgl>,
## #   camouflage <lgl>, element_control <lgl>, phasing <lgl>,
## #   astral_projection <lgl>, electrical_transport <lgl>,
## #   fire_control <lgl>, projection <lgl>, summoning <lgl>,
## #   enhanced_memory <lgl>, reflexes <lgl>, invulnerability <lgl>,
## #   energy_constructs <lgl>, force_fields <lgl>, self_sustenance <lgl>,
## #   anti_gravity <lgl>, empathy <lgl>, power_nullifier <lgl>,
## #   radiation_control <lgl>, psionic_powers <lgl>, elasticity <lgl>,
## #   substance_secretion <lgl>, elemental_transmogrification <lgl>,
## #   technopath_cyberpath <lgl>, photographic_reflexes <lgl>,
## #   seismic_power <lgl>, animation <lgl>, precognition <lgl>,
## #   mind_control <lgl>, fire_resistance <lgl>, power_absorption <lgl>,
## #   enhanced_hearing <lgl>, nova_force <lgl>, insanity <lgl>,
## #   hypnokinesis <lgl>, animal_control <lgl>, natural_armor <lgl>,
## #   intangibility <lgl>, enhanced_sight <lgl>,
## #   molecular_manipulation <lgl>, heat_generation <lgl>, adaptation <lgl>,
## #   gliding <lgl>, power_suit <lgl>, mind_blast <lgl>,
## #   probability_manipulation <lgl>, gravity_control <lgl>,
## #   regeneration <lgl>, light_control <lgl>, echolocation <lgl>,
## #   levitation <lgl>, toxin_and_disease_control <lgl>, banish <lgl>,
## #   energy_manipulation <lgl>, heat_resistance <lgl>, …
(hero_info <- clean_names(hero_info))
## # A tibble: 734 x 11
##       x1 name  gender eye_color race  hair_color height publisher
##    <dbl> <chr> <chr>  <chr>     <chr> <chr>       <dbl> <chr>    
##  1     0 A-Bo… Male   yellow    Human No Hair       203 Marvel C…
##  2     1 Abe … Male   blue      Icth… No Hair       191 Dark Hor…
##  3     2 Abin… Male   blue      Unga… No Hair       185 DC Comics
##  4     3 Abom… Male   green     Huma… No Hair       203 Marvel C…
##  5     4 Abra… Male   blue      Cosm… Black         -99 Marvel C…
##  6     5 Abso… Male   blue      Human No Hair       193 Marvel C…
##  7     6 Adam… Male   blue      <NA>  Blond         -99 NBC - He…
##  8     7 Adam… Male   blue      Human Blond         185 DC Comics
##  9     8 Agen… Female blue      <NA>  Blond         173 Marvel C…
## 10     9 Agen… Male   brown     Human Brown         178 Marvel C…
## # … with 724 more rows, and 3 more variables: skin_color <chr>,
## #   alignment <chr>, weight <dbl>

Q3 Removendo a primerira coluna hero_info.

library(dplyr)
select(hero_info,-1)
## # A tibble: 734 x 10
##    name  gender eye_color race  hair_color height publisher skin_color
##    <chr> <chr>  <chr>     <chr> <chr>       <dbl> <chr>     <chr>     
##  1 A-Bo… Male   yellow    Human No Hair       203 Marvel C… <NA>      
##  2 Abe … Male   blue      Icth… No Hair       191 Dark Hor… blue      
##  3 Abin… Male   blue      Unga… No Hair       185 DC Comics red       
##  4 Abom… Male   green     Huma… No Hair       203 Marvel C… <NA>      
##  5 Abra… Male   blue      Cosm… Black         -99 Marvel C… <NA>      
##  6 Abso… Male   blue      Human No Hair       193 Marvel C… <NA>      
##  7 Adam… Male   blue      <NA>  Blond         -99 NBC - He… <NA>      
##  8 Adam… Male   blue      Human Blond         185 DC Comics <NA>      
##  9 Agen… Female blue      <NA>  Blond         173 Marvel C… <NA>      
## 10 Agen… Male   brown     Human Brown         178 Marvel C… <NA>      
## # … with 724 more rows, and 2 more variables: alignment <chr>,
## #   weight <dbl>

Q4 Em hero_info converter todas as colunas com exceção da primeira para o tipo logical.

hero_powers %>% select(-1) %>% mutate_all(as.logical)
## # A tibble: 667 x 167
##    agility accelerated_hea… lantern_power_r… dimensional_awa…
##    <lgl>   <lgl>            <lgl>            <lgl>           
##  1 TRUE    FALSE            FALSE            FALSE           
##  2 FALSE   TRUE             FALSE            FALSE           
##  3 TRUE    TRUE             FALSE            FALSE           
##  4 FALSE   FALSE            TRUE             FALSE           
##  5 FALSE   TRUE             FALSE            FALSE           
##  6 FALSE   FALSE            FALSE            TRUE            
##  7 FALSE   FALSE            FALSE            FALSE           
##  8 FALSE   TRUE             FALSE            FALSE           
##  9 FALSE   FALSE            FALSE            FALSE           
## 10 FALSE   FALSE            FALSE            FALSE           
## # … with 657 more rows, and 163 more variables: cold_resistance <lgl>,
## #   durability <lgl>, stealth <lgl>, energy_absorption <lgl>,
## #   flight <lgl>, danger_sense <lgl>, underwater_breathing <lgl>,
## #   marksmanship <lgl>, weapons_master <lgl>, power_augmentation <lgl>,
## #   animal_attributes <lgl>, longevity <lgl>, intelligence <lgl>,
## #   super_strength <lgl>, cryokinesis <lgl>, telepathy <lgl>,
## #   energy_armor <lgl>, energy_blasts <lgl>, duplication <lgl>,
## #   size_changing <lgl>, density_control <lgl>, stamina <lgl>,
## #   astral_travel <lgl>, audio_control <lgl>, dexterity <lgl>,
## #   omnitrix <lgl>, super_speed <lgl>, possession <lgl>,
## #   animal_oriented_powers <lgl>, weapon_based_powers <lgl>,
## #   electrokinesis <lgl>, darkforce_manipulation <lgl>, death_touch <lgl>,
## #   teleportation <lgl>, enhanced_senses <lgl>, telekinesis <lgl>,
## #   energy_beams <lgl>, magic <lgl>, hyperkinesis <lgl>, jump <lgl>,
## #   clairvoyance <lgl>, dimensional_travel <lgl>, power_sense <lgl>,
## #   shapeshifting <lgl>, peak_human_condition <lgl>, immortality <lgl>,
## #   camouflage <lgl>, element_control <lgl>, phasing <lgl>,
## #   astral_projection <lgl>, electrical_transport <lgl>,
## #   fire_control <lgl>, projection <lgl>, summoning <lgl>,
## #   enhanced_memory <lgl>, reflexes <lgl>, invulnerability <lgl>,
## #   energy_constructs <lgl>, force_fields <lgl>, self_sustenance <lgl>,
## #   anti_gravity <lgl>, empathy <lgl>, power_nullifier <lgl>,
## #   radiation_control <lgl>, psionic_powers <lgl>, elasticity <lgl>,
## #   substance_secretion <lgl>, elemental_transmogrification <lgl>,
## #   technopath_cyberpath <lgl>, photographic_reflexes <lgl>,
## #   seismic_power <lgl>, animation <lgl>, precognition <lgl>,
## #   mind_control <lgl>, fire_resistance <lgl>, power_absorption <lgl>,
## #   enhanced_hearing <lgl>, nova_force <lgl>, insanity <lgl>,
## #   hypnokinesis <lgl>, animal_control <lgl>, natural_armor <lgl>,
## #   intangibility <lgl>, enhanced_sight <lgl>,
## #   molecular_manipulation <lgl>, heat_generation <lgl>, adaptation <lgl>,
## #   gliding <lgl>, power_suit <lgl>, mind_blast <lgl>,
## #   probability_manipulation <lgl>, gravity_control <lgl>,
## #   regeneration <lgl>, light_control <lgl>, echolocation <lgl>,
## #   levitation <lgl>, toxin_and_disease_control <lgl>, banish <lgl>,
## #   energy_manipulation <lgl>, heat_resistance <lgl>, …

Q5 Agrupando a coluna publisher no banco de dados hero_info em: Marvel, DC e Outros. Dica: usar combinação de dplyr::mutate() e dplyr::case_when().

glimpse(hero_info)
## Observations: 734
## Variables: 11
## $ x1         <dbl> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,…
## $ name       <chr> "A-Bomb", "Abe Sapien", "Abin Sur", "Abomination", "A…
## $ gender     <chr> "Male", "Male", "Male", "Male", "Male", "Male", "Male…
## $ eye_color  <chr> "yellow", "blue", "blue", "green", "blue", "blue", "b…
## $ race       <chr> "Human", "Icthyo Sapien", "Ungaran", "Human / Radiati…
## $ hair_color <chr> "No Hair", "No Hair", "No Hair", "No Hair", "Black", …
## $ height     <dbl> 203, 191, 185, 203, -99, 193, -99, 185, 173, 178, 191…
## $ publisher  <chr> "Marvel Comics", "Dark Horse Comics", "DC Comics", "M…
## $ skin_color <chr> NA, "blue", "red", NA, NA, NA, NA, NA, NA, NA, NA, NA…
## $ alignment  <chr> "good", "good", "good", "bad", "bad", "bad", "good", …
## $ weight     <dbl> 441, 65, 90, 441, -99, 122, -99, 88, 61, 81, 104, 108…
hero_info %>% distinct(publisher)
## # A tibble: 25 x 1
##    publisher        
##    <chr>            
##  1 Marvel Comics    
##  2 Dark Horse Comics
##  3 DC Comics        
##  4 NBC - Heroes     
##  5 Wildstorm        
##  6 Image Comics     
##  7 <NA>             
##  8 Icon Comics      
##  9 SyFy             
## 10 Hanna-Barbera    
## # … with 15 more rows
distinct(hero_info,publisher) 
## # A tibble: 25 x 1
##    publisher        
##    <chr>            
##  1 Marvel Comics    
##  2 Dark Horse Comics
##  3 DC Comics        
##  4 NBC - Heroes     
##  5 Wildstorm        
##  6 Image Comics     
##  7 <NA>             
##  8 Icon Comics      
##  9 SyFy             
## 10 Hanna-Barbera    
## # … with 15 more rows
hero_info <- hero_info %>% 
  mutate(publisher_new = case_when( publisher == "Marvel Comics" ~ "Marvel",
                                    publisher == "DC Comics" ~ "DC",
                                    publisher != c("Marvel Comics","DC Comics") ~ "Outros"
  ))
hero_info %>% count(publisher_new)
## # A tibble: 4 x 2
##   publisher_new     n
##   <chr>         <int>
## 1 DC              215
## 2 Marvel          388
## 3 Outros          116
## 4 <NA>             15

Q6 Em hero_info definir as raças exclusivas do DC Comics.

(race_dc <- hero_info %>% filter(publisher_new == "DC") %>% distinct(race))
## # A tibble: 30 x 1
##    race             
##    <chr>            
##  1 Ungaran          
##  2 Human            
##  3 <NA>             
##  4 Android          
##  5 God / Eternal    
##  6 Atlantean        
##  7 New God          
##  8 Bizarro          
##  9 Metahuman        
## 10 Human / Radiation
## # … with 20 more rows

Q7 Em hero_info mostre as cores dos olhos dos super heróis mais comuuns para cada sexo.

library(ggplot2)
library(forcats)
# Male
male_eye <- hero_info %>% filter(gender == "Male") %>% mutate(eye_color = eye_color %>% factor() %>% fct_infreq())
male_eye %>% ggplot(aes(eye_color)) +  geom_bar() +  theme(axis.text.x = element_text(face = "bold", color = "#993333", 
                                                                                      size = 12, angle = 45))

table(male_eye$eye_color)
## 
##         blue        brown          red        green        black 
##          143          107           37           30           17 
##       yellow        white         grey         gold        hazel 
##           16           13            6            3            3 
##       purple        amber blue / white         bown green / blue 
##            2            1            1            1            1 
##       silver  white / red yellow / red 
##            1            1            1
# Female
female_eye <- hero_info %>% filter(gender == "Female") %>% mutate(eye_color = eye_color %>% factor() %>% fct_infreq())
female_eye %>% ggplot(aes(eye_color)) +  geom_bar() +  theme(axis.text.x = element_text(face = "bold", color = "#993333", 
                                                                                         size = 12, angle = 45))

table(female_eye$eye_color)
## 
##                    blue                   green                   brown 
##                      76                      43                      15 
##                   black                     red                   hazel 
##                       5                       4                       3 
##                   white                  purple                  violet 
##                       3                       2                       2 
##                  yellow                   amber                  indigo 
##                       2                       1                       1 
## yellow (without irises)           yellow / blue 
##                       1                       1

Q8 Em hero_powers calcule o percentual de heróis que possui cada habilidade descrita nas colunas. Use a função dplyr::summarise_if para aplicar a função em todas as colunas da classe logical.

abl <- hero_powers %>% select(-1) %>% summarise_if(is.logical, sum) 
t(abl)*100/nrow(hero_powers)
##                                    [,1]
## agility                      36.2818591
## accelerated_healing          26.6866567
## lantern_power_ring            1.6491754
## dimensional_awareness         3.7481259
## cold_resistance               7.0464768
## durability                   38.5307346
## stealth                      18.8905547
## energy_absorption            11.5442279
## flight                       31.7841079
## danger_sense                  4.4977511
## underwater_breathing          3.1484258
## marksmanship                 17.8410795
## weapons_master               15.7421289
## power_augmentation            1.1994003
## animal_attributes             3.7481259
## longevity                    16.9415292
## intelligence                 23.6881559
## super_strength               53.9730135
## cryokinesis                   2.8485757
## telepathy                    13.7931034
## energy_armor                  1.1994003
## energy_blasts                22.0389805
## duplication                   2.3988006
## size_changing                 8.2458771
## density_control               2.2488756
## stamina                      43.3283358
## astral_travel                 0.5997001
## audio_control                 1.0494753
## dexterity                     0.8995502
## omnitrix                      0.1499250
## super_speed                  37.3313343
## possession                    1.1994003
## animal_oriented_powers        5.9970015
## weapon_based_powers           8.6956522
## electrokinesis                3.2983508
## darkforce_manipulation        1.4992504
## death_touch                   1.0494753
## teleportation                10.7946027
## enhanced_senses              13.3433283
## telekinesis                   9.1454273
## energy_beams                  6.2968516
## magic                         6.5967016
## hyperkinesis                  0.1499250
## jump                          9.7451274
## clairvoyance                  0.5997001
## dimensional_travel            3.4482759
## power_sense                   0.4497751
## shapeshifting                 9.8950525
## peak_human_condition          4.4977511
## immortality                  10.3448276
## camouflage                    3.1484258
## element_control               1.1994003
## phasing                       4.6476762
## astral_projection             4.3478261
## electrical_transport          0.1499250
## fire_control                  4.7976012
## projection                    0.2998501
## summoning                     0.5997001
## enhanced_memory               3.7481259
## reflexes                     24.5877061
## invulnerability              17.5412294
## energy_constructs             5.6971514
## force_fields                 12.8935532
## self_sustenance               5.5472264
## anti_gravity                  0.1499250
## empathy                       2.8485757
## power_nullifier               0.5997001
## radiation_control             1.0494753
## psionic_powers                7.3463268
## elasticity                    1.6491754
## substance_secretion           2.5487256
## elemental_transmogrification  0.8995502
## technopath_cyberpath          3.4482759
## photographic_reflexes         0.4497751
## seismic_power                 0.4497751
## animation                     0.7496252
## precognition                  3.2983508
## mind_control                  3.2983508
## fire_resistance               2.6986507
## power_absorption              1.7991004
## enhanced_hearing             10.7946027
## nova_force                    0.2998501
## insanity                      0.7496252
## hypnokinesis                  3.4482759
## animal_control                1.3493253
## natural_armor                 5.3973013
## intangibility                 2.9985007
## enhanced_sight                3.7481259
## molecular_manipulation        6.2968516
## heat_generation               3.5982009
## adaptation                    0.7496252
## gliding                       1.4992504
## power_suit                    4.9475262
## mind_blast                    1.7991004
## probability_manipulation      1.3493253
## gravity_control               2.3988006
## regeneration                  4.1979010
## light_control                 2.2488756
## echolocation                  0.2998501
## levitation                    3.8980510
## toxin_and_disease_control     1.4992504
## banish                        0.1499250
## energy_manipulation           7.7961019
## heat_resistance               6.4467766
## natural_weapons               8.6956522
## time_travel                   4.9475262
## enhanced_smell                4.7976012
## illusions                     5.6971514
## thirstokinesis                0.1499250
## hair_manipulation             0.1499250
## illumination                  0.2998501
## omnipotent                    1.0494753
## cloaking                      1.0494753
## changing_armor                0.1499250
## power_cosmic                  1.0494753
## biokinesis                    0.1499250
## water_control                 1.9490255
## radiation_immunity            1.4992504
## vision_telescopic             6.4467766
## toxin_and_disease_resistance  7.1964018
## spatial_awareness             0.1499250
## energy_resistance             1.0494753
## telepathy_resistance          4.9475262
## molecular_combustion          0.2998501
## omnilingualism                3.1484258
## portal_creation               0.5997001
## magnetism                     1.6491754
## mind_control_resistance       1.7991004
## plant_control                 1.1994003
## sonar                         0.5997001
## sonic_scream                  0.8995502
## time_manipulation             2.9985007
## enhanced_touch                1.0494753
## magic_resistance              0.8995502
## invisibility                  3.2983508
## sub_mariner                   2.9985007
## radiation_absorption          1.0494753
## intuitive_aptitude            0.1499250
## vision_microscopic            2.8485757
## melting                       0.2998501
## wind_control                  0.4497751
## super_breath                  3.4482759
## wallcrawling                  5.0974513
## vision_night                  5.0974513
## vision_infrared               3.2983508
## grim_reaping                  0.4497751
## matter_absorption             1.6491754
## the_force                     0.8995502
## resurrection                  2.2488756
## terrakinesis                  0.2998501
## vision_heat                   2.8485757
## vitakinesis                   0.2998501
## radar_sense                   0.8995502
## qwardian_power_ring           0.2998501
## weather_control               1.1994003
## vision_x_ray                  3.4482759
## vision_thermal                3.4482759
## web_creation                  2.0989505
## reality_warping               2.3988006
## odin_force                    0.2998501
## symbiote_costume              1.3493253
## speed_force                   0.1499250
## phoenix_force                 0.1499250
## molecular_dissipation         0.1499250
## vision_cryo                   0.2998501
## omnipresent                   0.2998501
## omniscient                    0.2998501
df1 <- tibble(poderes=names(hero_powers)[-1],freq=t(abl)*100/nrow(hero_powers))

Q9 Repita o exercício anterior usando a abordagem tidy. Converta o formato do dataframe hero_powers para o formato long. Passando a ter 3 colunas: hero_names, poder e possui_poder. Use a função tidyr::gather(). Então calcule a média da coluna possui_poder agrupado pela coluna poder.

library(tidyr)
hero_powers %>%
  gather("poderes","possui_poderes",-hero_names) %>%
  group_by(poderes, possui_poderes) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n) * 100) %>% 
  ungroup()
## # A tibble: 334 x 4
##    poderes             possui_poderes     n   freq
##    <chr>               <lgl>          <int>  <dbl>
##  1 accelerated_healing FALSE            489 73.3  
##  2 accelerated_healing TRUE             178 26.7  
##  3 adaptation          FALSE            662 99.3  
##  4 adaptation          TRUE               5  0.750
##  5 agility             FALSE            425 63.7  
##  6 agility             TRUE             242 36.3  
##  7 animal_attributes   FALSE            642 96.3  
##  8 animal_attributes   TRUE              25  3.75 
##  9 animal_control      FALSE            658 98.7  
## 10 animal_control      TRUE               9  1.35 
## # … with 324 more rows
hero_powers %>%
  gather("poderes","possui_poderes",-hero_names) %>%
  group_by(poderes, possui_poderes) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n) * 100) %>% 
  ungroup() %>% filter(possui_poderes==TRUE)
## # A tibble: 167 x 4
##    poderes                possui_poderes     n   freq
##    <chr>                  <lgl>          <int>  <dbl>
##  1 accelerated_healing    TRUE             178 26.7  
##  2 adaptation             TRUE               5  0.750
##  3 agility                TRUE             242 36.3  
##  4 animal_attributes      TRUE              25  3.75 
##  5 animal_control         TRUE               9  1.35 
##  6 animal_oriented_powers TRUE              40  6.00 
##  7 animation              TRUE               5  0.750
##  8 anti_gravity           TRUE               1  0.150
##  9 astral_projection      TRUE              29  4.35 
## 10 astral_travel          TRUE               4  0.600
## # … with 157 more rows
hero_powers %>%
  gather("poderes","possui_poderes",-hero_names) %>%
  group_by(poderes, possui_poderes) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n) * 100) %>% 
  ungroup() %>% filter(possui_poderes==FALSE)
## # A tibble: 167 x 4
##    poderes                possui_poderes     n  freq
##    <chr>                  <lgl>          <int> <dbl>
##  1 accelerated_healing    FALSE            489  73.3
##  2 adaptation             FALSE            662  99.3
##  3 agility                FALSE            425  63.7
##  4 animal_attributes      FALSE            642  96.3
##  5 animal_control         FALSE            658  98.7
##  6 animal_oriented_powers FALSE            627  94.0
##  7 animation              FALSE            662  99.3
##  8 anti_gravity           FALSE            666  99.9
##  9 astral_projection      FALSE            638  95.7
## 10 astral_travel          FALSE            663  99.4
## # … with 157 more rows

Q10 Junte os dois dataframes em um único chamado de hero.

names(hero_info)[2] <- "hero_names"
(hero <- inner_join(hero_info,hero_powers,by="hero_names"))
## # A tibble: 660 x 179
##       x1 hero_names gender eye_color race  hair_color height publisher
##    <dbl> <chr>      <chr>  <chr>     <chr> <chr>       <dbl> <chr>    
##  1     0 A-Bomb     Male   yellow    Human No Hair       203 Marvel C…
##  2     1 Abe Sapien Male   blue      Icth… No Hair       191 Dark Hor…
##  3     2 Abin Sur   Male   blue      Unga… No Hair       185 DC Comics
##  4     3 Abominati… Male   green     Huma… No Hair       203 Marvel C…
##  5     4 Abraxas    Male   blue      Cosm… Black         -99 Marvel C…
##  6     5 Absorbing… Male   blue      Human No Hair       193 Marvel C…
##  7     6 Adam Monr… Male   blue      <NA>  Blond         -99 NBC - He…
##  8     7 Adam Stra… Male   blue      Human Blond         185 DC Comics
##  9     9 Agent Bob  Male   brown     Human Brown         178 Marvel C…
## 10    10 Agent Zero Male   <NA>      <NA>  <NA>          191 Marvel C…
## # … with 650 more rows, and 171 more variables: skin_color <chr>,
## #   alignment <chr>, weight <dbl>, publisher_new <chr>, agility <lgl>,
## #   accelerated_healing <lgl>, lantern_power_ring <lgl>,
## #   dimensional_awareness <lgl>, cold_resistance <lgl>, durability <lgl>,
## #   stealth <lgl>, energy_absorption <lgl>, flight <lgl>,
## #   danger_sense <lgl>, underwater_breathing <lgl>, marksmanship <lgl>,
## #   weapons_master <lgl>, power_augmentation <lgl>,
## #   animal_attributes <lgl>, longevity <lgl>, intelligence <lgl>,
## #   super_strength <lgl>, cryokinesis <lgl>, telepathy <lgl>,
## #   energy_armor <lgl>, energy_blasts <lgl>, duplication <lgl>,
## #   size_changing <lgl>, density_control <lgl>, stamina <lgl>,
## #   astral_travel <lgl>, audio_control <lgl>, dexterity <lgl>,
## #   omnitrix <lgl>, super_speed <lgl>, possession <lgl>,
## #   animal_oriented_powers <lgl>, weapon_based_powers <lgl>,
## #   electrokinesis <lgl>, darkforce_manipulation <lgl>, death_touch <lgl>,
## #   teleportation <lgl>, enhanced_senses <lgl>, telekinesis <lgl>,
## #   energy_beams <lgl>, magic <lgl>, hyperkinesis <lgl>, jump <lgl>,
## #   clairvoyance <lgl>, dimensional_travel <lgl>, power_sense <lgl>,
## #   shapeshifting <lgl>, peak_human_condition <lgl>, immortality <lgl>,
## #   camouflage <lgl>, element_control <lgl>, phasing <lgl>,
## #   astral_projection <lgl>, electrical_transport <lgl>,
## #   fire_control <lgl>, projection <lgl>, summoning <lgl>,
## #   enhanced_memory <lgl>, reflexes <lgl>, invulnerability <lgl>,
## #   energy_constructs <lgl>, force_fields <lgl>, self_sustenance <lgl>,
## #   anti_gravity <lgl>, empathy <lgl>, power_nullifier <lgl>,
## #   radiation_control <lgl>, psionic_powers <lgl>, elasticity <lgl>,
## #   substance_secretion <lgl>, elemental_transmogrification <lgl>,
## #   technopath_cyberpath <lgl>, photographic_reflexes <lgl>,
## #   seismic_power <lgl>, animation <lgl>, precognition <lgl>,
## #   mind_control <lgl>, fire_resistance <lgl>, power_absorption <lgl>,
## #   enhanced_hearing <lgl>, nova_force <lgl>, insanity <lgl>,
## #   hypnokinesis <lgl>, animal_control <lgl>, natural_armor <lgl>,
## #   intangibility <lgl>, enhanced_sight <lgl>,
## #   molecular_manipulation <lgl>, heat_generation <lgl>, adaptation <lgl>,
## #   gliding <lgl>, power_suit <lgl>, mind_blast <lgl>,
## #   probability_manipulation <lgl>, gravity_control <lgl>, …
glimpse(hero)
## Observations: 660
## Variables: 179
## $ x1                           <dbl> 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, …
## $ hero_names                   <chr> "A-Bomb", "Abe Sapien", "Abin Sur",…
## $ gender                       <chr> "Male", "Male", "Male", "Male", "Ma…
## $ eye_color                    <chr> "yellow", "blue", "blue", "green", …
## $ race                         <chr> "Human", "Icthyo Sapien", "Ungaran"…
## $ hair_color                   <chr> "No Hair", "No Hair", "No Hair", "N…
## $ height                       <dbl> 203, 191, 185, 203, -99, 193, -99, …
## $ publisher                    <chr> "Marvel Comics", "Dark Horse Comics…
## $ skin_color                   <chr> NA, "blue", "red", NA, NA, NA, NA, …
## $ alignment                    <chr> "good", "good", "good", "bad", "bad…
## $ weight                       <dbl> 441, 65, 90, 441, -99, 122, -99, 88…
## $ publisher_new                <chr> "Marvel", "Outros", "DC", "Marvel",…
## $ agility                      <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ accelerated_healing          <lgl> TRUE, TRUE, FALSE, TRUE, FALSE, FAL…
## $ lantern_power_ring           <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, F…
## $ dimensional_awareness        <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ cold_resistance              <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, T…
## $ durability                   <lgl> TRUE, TRUE, FALSE, FALSE, FALSE, TR…
## $ stealth                      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ energy_absorption            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ flight                       <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ danger_sense                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ underwater_breathing         <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ marksmanship                 <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ weapons_master               <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ power_augmentation           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ animal_attributes            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ longevity                    <lgl> TRUE, TRUE, FALSE, FALSE, FALSE, FA…
## $ intelligence                 <lgl> FALSE, TRUE, FALSE, TRUE, TRUE, FAL…
## $ super_strength               <lgl> TRUE, TRUE, FALSE, TRUE, TRUE, TRUE…
## $ cryokinesis                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ telepathy                    <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ energy_armor                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ energy_blasts                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ duplication                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ size_changing                <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ density_control              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ stamina                      <lgl> TRUE, TRUE, FALSE, TRUE, FALSE, FAL…
## $ astral_travel                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ audio_control                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ dexterity                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ omnitrix                     <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ super_speed                  <lgl> FALSE, FALSE, FALSE, TRUE, TRUE, FA…
## $ possession                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ animal_oriented_powers       <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ weapon_based_powers          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ electrokinesis               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ darkforce_manipulation       <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ death_touch                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ teleportation                <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ enhanced_senses              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ telekinesis                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ energy_beams                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ magic                        <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ hyperkinesis                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ jump                         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ clairvoyance                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ dimensional_travel           <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ power_sense                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ shapeshifting                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ peak_human_condition         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ immortality                  <lgl> FALSE, TRUE, FALSE, FALSE, TRUE, FA…
## $ camouflage                   <lgl> TRUE, FALSE, FALSE, FALSE, FALSE, F…
## $ element_control              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ phasing                      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ astral_projection            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ electrical_transport         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ fire_control                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ projection                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ summoning                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ enhanced_memory              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ reflexes                     <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ invulnerability              <lgl> FALSE, FALSE, FALSE, TRUE, TRUE, TR…
## $ energy_constructs            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ force_fields                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ self_sustenance              <lgl> TRUE, FALSE, FALSE, FALSE, FALSE, F…
## $ anti_gravity                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ empathy                      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ power_nullifier              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ radiation_control            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ psionic_powers               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ elasticity                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ substance_secretion          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ elemental_transmogrification <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ technopath_cyberpath         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ photographic_reflexes        <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ seismic_power                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ animation                    <lgl> FALSE, FALSE, FALSE, TRUE, FALSE, F…
## $ precognition                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ mind_control                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ fire_resistance              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ power_absorption             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ enhanced_hearing             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ nova_force                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ insanity                     <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ hypnokinesis                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ animal_control               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ natural_armor                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ intangibility                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ enhanced_sight               <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ molecular_manipulation       <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, T…
## $ heat_generation              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ adaptation                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ gliding                      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ power_suit                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ mind_blast                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ probability_manipulation     <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ gravity_control              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ regeneration                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ light_control                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ echolocation                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ levitation                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ toxin_and_disease_control    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ banish                       <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ energy_manipulation          <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ heat_resistance              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ natural_weapons              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ time_travel                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ enhanced_smell               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ illusions                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ thirstokinesis               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ hair_manipulation            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ illumination                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ omnipotent                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ cloaking                     <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ changing_armor               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ power_cosmic                 <lgl> FALSE, FALSE, FALSE, FALSE, TRUE, F…
## $ biokinesis                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ water_control                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ radiation_immunity           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_telescopic            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ toxin_and_disease_resistance <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ spatial_awareness            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ energy_resistance            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ telepathy_resistance         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ molecular_combustion         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ omnilingualism               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ portal_creation              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ magnetism                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ mind_control_resistance      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ plant_control                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ sonar                        <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ sonic_scream                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ time_manipulation            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ enhanced_touch               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ magic_resistance             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ invisibility                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ sub_mariner                  <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, F…
## $ radiation_absorption         <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ intuitive_aptitude           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_microscopic           <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ melting                      <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ wind_control                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ super_breath                 <lgl> FALSE, FALSE, FALSE, TRUE, FALSE, F…
## $ wallcrawling                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_night                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_infrared              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ grim_reaping                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ matter_absorption            <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ the_force                    <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ resurrection                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ terrakinesis                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_heat                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vitakinesis                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ radar_sense                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ qwardian_power_ring          <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ weather_control              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_x_ray                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_thermal               <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ web_creation                 <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ reality_warping              <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ odin_force                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ symbiote_costume             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ speed_force                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ phoenix_force                <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ molecular_dissipation        <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ vision_cryo                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ omnipresent                  <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …
## $ omniscient                   <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, …

Q11 No novo dataframe hero calcule o percentual de heróis de cada editora que são telepatas.

hero %>% 
  filter(telepathy==TRUE) %>%
  group_by(publisher_new) %>%
  summarise(n = n()) %>%
  mutate(freq_telepathy = n / sum(n) * 100) %>% 
  ungroup()
## # A tibble: 3 x 3
##   publisher_new     n freq_telepathy
##   <chr>         <int>          <dbl>
## 1 DC               19           20.7
## 2 Marvel           57           62.0
## 3 Outros           16           17.4

Q12 No dataframe hero, selecione as colunas names, publisher, flight, weight, filtre os heróis que podem voar e retorne os 10 pesos maiores.

# Q12
hero %>%
  select(hero_names,publisher,flight,weight) %>%
    filter(flight==TRUE) %>% top_n(weight, n=10) %>%
      arrange(desc(weight))
## # A tibble: 10 x 4
##    hero_names   publisher     flight weight
##    <chr>        <chr>         <lgl>   <dbl>
##  1 Darkseid     DC Comics     TRUE      817
##  2 Thanos       Marvel Comics TRUE      443
##  3 Onslaught    Marvel Comics TRUE      405
##  4 Spawn        Image Comics  TRUE      405
##  5 Machine Man  Marvel Comics TRUE      383
##  6 Living Brain Marvel Comics TRUE      360
##  7 MODOK        Marvel Comics TRUE      338
##  8 Ultron       Marvel Comics TRUE      331
##  9 Thor         Marvel Comics TRUE      288
## 10 Gladiator    Marvel Comics TRUE      268

Q13 Salve o dataframe chamado hero no arquivo hero_completo.csv usando a função readr::write.csv().

write_csv(x = hero,path = "herois_completo.csv")