讀入pokemon資料
pokemon <- read.csv("Pokemon.csv")
type1 <- unique(pokemon$Type.1)
print(type1)
## [1] "Grass" "Fire" "Water" "Bug" "Normal" "Poison"
## [7] "Electric" "Ground" "Fairy" "Fighting" "Psychic" "Rock"
## [13] "Ghost" "Ice" "Dragon" "Dark" "Steel" "Flying"
table(pokemon$Type.1)
##
## Bug Dark Dragon Electric Fairy Fighting Fire Flying
## 69 31 32 44 17 27 52 4
## Ghost Grass Ground Ice Normal Poison Psychic Rock
## 32 70 32 24 98 28 57 44
## Steel Water
## 27 112
avg_legendary <- aggregate(Total ~ Legendary, data = pokemon, FUN = mean)
print(avg_legendary)
## Legendary Total
## 1 False 417.2136
## 2 True 637.3846
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")])
## Name Total
## 423 KyogrePrimal Kyogre 770
## 542 Palkia 680
## 422 Kyogre 670
## 142 GyaradosMega Gyarados 640
## 284 SwampertMega Swampert 635
Ans:在水屬性中,總屬性值最高的分別是KyogrePrimal Kyogre、
Palkia、Kyogre、GyaradosMega Gyarados、SwampertMega Swampert