-1

I've scraped two tables into R, trimmed them, and now I seek to create new tables by splitting one of the columns of the originals into two. To do this, I've written the following code:

page.201702050atl = read_html("http://www.pro-football-reference.com/boxscores/201702050atl.htm")
comments.201702050atl = page.201702050atl %>% html_nodes(xpath = "//comment()")
home.drives.201702050atl = comments.201702050atl[43] %>% html_text() %>% read_html() %>% html_node("#home_drives") %>% html_table()
home.drives.201702050atl.a = home.drives.201702050atl[ , 2:8]
LOS.home.201702050atl = t(data.frame(strsplit(as.character(home.drives.201702050atl.a$LOS), " ", 2)))
LOS.vis.201702050atl = t(data.frame(strsplit(as.character(home.drives.201702050atl.a$LOS), " ", 2)))

I've run this code countless times on countless other tables; but, on these two (nearly identical) tables, I seem to be having a problem that I don't understand:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 2, 0

Can someone please translate this error message into English for me? What is wrong in this particular case? Finally, how do I fix it?

EDIT:

There is a missing cell in row 5 of home.drives.201702050atl. Initially I thought this might be the problem; however, that is why I included the second table. In the second table, there is no missing cell; and yet, I encounter the same error. While it is similar to that of the first table, I did not include the entirety of the coding of the second table in my original post. Please find it below:

> page.201702050atl = read_html("http://www.pro-football-reference.com/boxscores/201702050atl.htm")
> comments.201702050atl = page.201702050atl %>% html_nodes(xpath = "//comment()")
> vis.drives.201702050atl = comments.201702050atl[44] %>% html_text() %>% read_html() %>% html_node("#vis_drives") %>% html_table()
> vis.drives.201702050atl.a = vis.drives.201702050atl[ , 2:8]
> LOS.vis.201702050atl = t(data.frame(strsplit(as.character(home.drives.201702050atl.a$LOS), " ", 2)))
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 2, 0
DataProphets
  • 156
  • 3
  • 17
  • Just execute your code step by step and look at the created objects. Then you will see where the chain breaks and will find a solution. – ottlngr Mar 10 '17 at 07:53
  • Possible duplicate of [this](http://stackoverflow.com/questions/26147558/arguments-imply-differing-number-of-rows-8-20), [this](http://stackoverflow.com/questions/30270946/arguments-imply-differing-number-of-rows-2-4-3-5) and [this](http://stackoverflow.com/questions/35814146/r-error-arguments-imply-differing-number-of-rows)? – zx8754 Mar 10 '17 at 07:53
  • I've gone line by line and only encounter an error in line 5, the line which seeks to make a new table. As for the duplication comment, while the posts you cite also encounter the "differing number of rows" error, the build up to it is completely different. – DataProphets Mar 10 '17 at 09:49

1 Answers1

0

The error is from the fifth line of your code.

home.drives.201702050atl.a %>% 
    `$`(LOS) %>%
    as.character() %>%
    strsplit(., " ", 2) %>%
    purrr::map_int(length)

[1] 2 2 2 2 0 2 2 2 2 2 2

Length of the fifth element is 0. The error is the result of creating a data frame with different number of rows. Getting rid of the fifth element might solve the problem.

  • That's what I thought the problem was too, initially. However, there are no missing cells in the second table and I encounter the same error. I should have been more thorough in my explanation of the second table. I will edit my initial post to include the entirety of its coding. – DataProphets Mar 10 '17 at 09:24