Recently a colleague asked if I could use R/statistics to form a dream soccer team from a pool of soccer players, given basic player information like name, club, cost, points.

The idea is to form a team with your preferred configuration of number of defenders, mid fielders and strikers to maximize your total team points without exceeding your budget.

I wrote some R code (linear optimization) to get the answer. Check it out. The code allows configurable constraints to let you create your own dream team.

1) Number of goalkeepers 2) Number of defenders 3) Number of mid fielders 4) Number of strikers 5) Total team cost ($$$ you’ll spend on this team) 6) Maximum number of players from a team

Here’s a team I put together based on this code with following configuration.

1) Number of goalkeepers = 1 2) Number of defenders = 4 3) Number of mid fielders = 3 4) Number of strikers = 3 5) Total team cost = 50 GBP 6) Maximum number of players from a team = 4

DISCLAIMER: Soccer isn’t my favorite sport (its Cricket , if you’re curious 😉 and I don’t play fantasy football.