讀入pokemon資料

pokemon <- read.csv(“Pokemon.csv”)

Q1 Which primary types (Type 1) appear in the data?

type1 <- unique(pokemon$Type.1)

print(type1)

 [1] "Grass"    "Fire"     "Water"    "Bug"      "Normal"    
 
 [6] "Poison"   "Electric" "Ground"   "Fairy"    "Fighting" 
 
 [11] "Psychic"  "Rock"     "Ghost"    "Ice"      "Dragon"   
 
 [16] "Dark"     "Steel"    "Flying"  

Q2 How many Pokémon does each primary type have?

table(pokemon$Type.1)

 Bug     Dark   Dragon Electric    Fairy Fighting   
 69       31       32       44       17     27 
 
 Fire   Flying    Ghost    Grass   Ground   Ice  
 52        4       32       70       32       24    
 Normal   Poison  Psychic   Rock    Steel   Water
 98       28       57       44       27      112

Q3 Is the average Total of legendary Pokémon higher than non-legendary?

avg_legendary <- aggregate(Total ~ Legendary, data = pokemon, FUN = mean)

print(avg_legendary)

Ans:legendary Pokémon higher than non-legendary

Legendary    Total 1     
False 417.2136 2      
True 637.3846

Q4 Among Water Pokémon, which five have the highest Total?

water_pokemon <- subset(pokemon, Type.1 == “Water”)

top5water <- water_pokemon[order(water_pokemon$Total, decreasing = TRUE), ]

tp5water <- head(top5water, 5)

print(tp5water[, c(“Name”, “Total”)])

Ans:在水屬性中,總屬性值最高的分別是KyogrePrimal Kyogre、
Palkia、Kyogre、GyaradosMega Gyarados、SwampertMega Swampert