You can't change the type of infantry you can only upgrade them.
Having said that it is good to have a spear army with archers for defense.
And a sword and cavarly army for attack.
It is always good to have a few units of each type. Even in attack archers can be useful to bait units off hills. And in defense horse archers are good to bait enemies to a particular flank... it is a lot easier to defend one flank as a player then have them swarm both sides.
There is really only a few types of units.
Spearmen... good against Cav.
Swords... good against spear.
Archers... good against foot troops... if no one is defending them they get eaten by Cav.
Cav... good against flanks and archers. In equal numbers they will beat anyone including spears. However a humble spear unit vs a Royal Knight (200:20) will win and the cost in money is a lot cheaper for the spears.
Horse Archers... good combination of Archers and Cav... avoid melee unless you attack the rear of an engaged unit. Also due to their speed excellent at chasing down routers.
Bookmarks