So i want to write a double for loop in R but I got a problem. Here is my code.
pokemon_stats_type <- select(pokemon, attack, sp_attack, defense, sp_defense, hp, speed, types)
List_of_types <- c("fire", "water", "grass", "steel", "bug", "poison", "fairy", "electric", "flying", "dark", "ghost", "normal", "fighting", "ground", "rock", "psychic", "dragon", "ice")
List_of_stats <- c("Attack", "sp_attack")
attack <- c()
for (type in List_of_types){
set <- subset(pokemon, grepl(type, pokemon$types))
for (stat in List_of_stats){
print(mean(set$stat))
}
}
So if I run this code, i only get NA. If I change set$stat to set$attack or set$"attack" it prints values of the attack stats. But I want to loop it so it also prints te sp_attack stats.
Can please someone help me I don't know what to do?