I am trying to import a table from a web page using the readHtmlTable function, this is the first few rows of what the data looks like when it is in R.
Event Athlete Country Result Medal year
1 100m Men Tom Burke USA 12.0 GOLD 1896
2 Fritz Hofmann DEU 12.2 est. SILVER 1896
3 Francis Lane USA 12.6 BRONZE 1896
4 Alajos Szokolyi HUN 12.6 est. BRONZE 1896
5 400m Men Tom Burke USA 54.2 GOLD 1896
6 Herbert Jamison USA n/a SILVER 1896
7 Charles Gmelin GBR n/a BRONZE 1896
8 800m Men Teddy Flack AUS 2:11.0 GOLD 1896
9 Nֳ¡ndor Dֳ¡ni HUN 2:11.8 est. SILVER 1896
10 Demitrios Golemis GRE n/a BRONZE 1896
Now if you look at the event column you can see some of the rows of the event field empty, this is the way the table is on the website, what I am looking for is the most efficient way to fill those blanks so at the end it should look like this
Event Athlete Country Result Medal year
1 100m Men Tom Burke USA 12.0 GOLD 1896
2 100m Men Fritz Hofmann DEU 12.2 est. SILVER 1896
3 100m Men Francis Lane USA 12.6 BRONZE 1896
4 100m Men Alajos Szokolyi HUN 12.6 est. BRONZE 1896
5 400m Men Tom Burke USA 54.2 GOLD 1896
Basically every time a field in the Event column is empty I need to fill it with the last value that was not empty. The column is saved in R as a factor and I know that technically I can do this using a for loop and going over all of the vector elements but this is very time consuming considering the fat that there are about 300000 rows in this table. I am hoping for something more efficient
na.locffrom the zoo package. Seelibrary(zoo); ?na.locffor help and google forna.locfto find many additional examples.