Week 5 USISSL League Table

California remains at the top of the table and actually increased its lead over 2nd place Texas. There was no change in the order of the top six states, although the gap between 6 and 7 shrunk by one point. North Carolina pulled even with Massachusetts, while Arizona tumbled two places to 11th. Virginia continues to occupy the foot of the table.

Here is the USISSL week 5 league table:

       State Team Total Points
1      California          253
2           Texas          180
3            Ohio          138
4      New Jersey          108
5        New York          107
6    Pennsylvania           87
7   Massachusetts           75
8  North Carolina           75
9         Florida           72
10        Georgia           66
11        Arizona           65
12      Minnesota           37
13     Washington           35
14       Virginia           20


As before, there are some aesthetic improvements that I need to make with the table and I still want to add a column indicating how many players each team is able to field each week, but this time I was concentrating on developing a way to update the players' MLS fantasy league points, one that would not be too time-consuming and laborious. I experimented with web page scraping, but I found that I could not make it work for the MLS Fantasy league web page. Furthermore (and rather unhelpfully), the MLS Fantasy points are not available for all players on one web page; rather, they are distributed over 20 or more separate pages. I had to get a little creative in my approach, which is challenging given my very limited R skill set.

I ultimately decided to sort the MLS Fantasy points by MLS team, which conveniently put each team's complete roster on a single web page, one for each team. I was able to copy the tables into Excel and save them as .csv files. I then used some of the code that I employed in previous projects in order to match player names between my USISSL data frame and each team's updated fantasy league points data frame, followed (within the same line of code) by adding a column with each player's latest points total to my USISSL data frame. Then I filtered my USISSL data frame to create individual team data frames. In order to accomplish this, I wrote three lines of code for each team. Here is an example:

> SEA<-read.csv("SEA.csv")
> USISSL$Points<-SEA$Pts[match(USISSL$Last.Name, SEA$Player)]
> SEA_f<-filter(USISSL, Team=="Seattle")

I created individual team data frames because the MLS Fantasy data has only the players' last names, and they are not all unique. I couldn't think of another way to minimize surname conflicts, and my method still will fail if one team has two players with the same surname. I'll deal with that when I have to.

I then checked each team data frame for "NA"s in the "Points" column and corrected them. Nearly every team had a couple of "NA"s, most of which were due to the MLS Fantasy tables adding a large, red exclamation point next to the names of players who are out of action for some reason. This flag was imported as a blank space at the end of the player's name, which was hard to spot at first. I think I should be able to remove these spaces with some more lines of code, but this time I fixed them all individually "by hand".

The next step was to combine all of the team data frames into one league data frame, which I accomplished using "rbind". From there, I just imported the same code I used for last week's league table, making a few minor modifications to make sure that data frame names matched. And once again, it worked!

Now that I have these pieces in place, I can turn more attention to aesthetic concerns, after which I will explore new, more elegant ways to accomplish the same result. Onward!

Comments

Popular Posts