I'm trying to scrape standard stats of players playing for soccer teams using RStudio. I'm able to extract the information into lists but not able to visualize them as data frames, it gives me this error (Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 33, 27, 24, 35, 5, 4, 54, 38, 18, 2, 1) I'm quite a noob in R and I can't think of a way to solve it, here is the code that I am using, and the page from which I am trying to extract the data, any help is very welcomed!!!
https://fbref.com/en/squads/2b390eca/2016-2017/Athletic-Bilbao
install.packages('rvest')
install.packages('plyr')
install.packages('dplyr')
library(rvest)
library(plyr)
library(dplyr)
years = c(2017:2018)
urls = list()
for (i in 1:length(years)) {
url = paste0('https://fbref.com/en/squads/2b390eca/',years[i],'-',years[i+1],'/Athletic-Bilbao')
urls[[i]] = url #https://fbref.com/en/squads/d5348c80/',years1[i],'-',years2[i+1],'/AEK-Athens
}
tbl = list()
years = 2017
j = 1
for (j in seq_along(urls)) {
tbl[[j]] = urls[[j]] %>%
read_html() %>%
html_nodes("table") %>%
html_table()
tbl[[j]]$Year = years
j = j+1
years = years+1
}
Data = ldply(tbl,data.frame)