I have seen just as many pictures for armies of the time fielding swords as I have for them fielding spears as their main infantry equipment.
I am not exactly asking whether a sword or a spear was better or worse for fighting infantry,
Instead rather I am seeking to know whether and why the spear or sword was more common amongst the ranks of Infantry in large armies..... and whether this descision was a cultural prefrence, whether one was clearly more advantageous or if it was simply an affordability issue for kings and nobles.
Note:
Thank you,
I am seeking to know whether and why the spear or sword was more common amongst the ranks of Infantry in large armies
At least in the later Medieval period, swords were often more common. However, the spear (or other polearms) was the main infantry weapon. This is not as contradictory as it might seem - spearmen typically carried a sword as a sidearm, and other infantry (e.g., archers, crossbowmen, arquebusiers) also usually carried swords. Thus, there were more swords on the battlefield, but the main weapons were bows/crossbows and spears/polearms.
In the early Medieval period, there were far fewer swords. Infantry would typically use a spear or bow as their main weapon, and might carry an axe or large knife as their sidearm.
For a past answer of mine on this, see https://www.reddit.com/r/AskHistorians/comments/ae3b17/if_spears_were_generally_better_than_swords_why/
Cavalry would typically carry a lance as their main weapon, and a sword as their sidearm (and often an additional weapon such as an axe or mace). They would typically make more use of their sword, since the lance could be easily lost or broken. Where Medieval cavalry used a bow as their main weapon (e.g., sometimes in Eastern Europe, even if we restrict the question to Europe), the sword was still a common sidearm (and sometimes a lance was carried as well).
Warhorses were usually expensive. Even if (average) swords were expensive, they were still usually cheaper than horses, or at worst similar in price (and would not need to be replaced as often). Typically, cavalry could afford swords, so even in the early Medieval period, swords would still be common for cavalry.
Post-Medieval, we see more use of swords by cavalry. This was often due to replacement of the lance by pistols or carbines, as I discussed in https://www.reddit.com/r/AskHistorians/comments/ekcozp/considering_how_effective_the_lance_was_at_the/
Swords were not useless. There were plenty of good reasons to carry them as sidearms. Your spear might break, or you might be fighting in very close quarters, or if an archer/crossbowman, be out of ammunition or not have time to reload. Even when not the main weapons for most infantry and cavalry, they would be used on the battlefield.
A sword also made a good off-duty (or civilian) sidearm. When swords were cheap enough for soldiers to afford, why not? Swords were often cheaper than helmets and mail, things that professional soldiers often owned. For part-time militia who might not be able to afford armour, swords might be too expensive. For professionals such as knights and mercenaries, swords were usually affordable.