2017-03-10 3 views
-1

R에 두 개의 테이블을 긁어서 잘라 냈다. 이제 원본의 열 중 하나를 두 개로 분할하여 새 테이블을 만들려고한다. . 이렇게하려면 다음 코드를 작성했습니다.R의 오류 메시지 해석, 하나의 열을 두 개로 나누고 새로운 데이터 프레임 만들기

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))) 

나는 무수히 많은 다른 테이블에서이 코드를 무한히 실행했습니다.

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

누군가가 나를 영어로이 오류 메시지가 번역시겠습니까 :하지만,이 두 가지 (거의 동일) 테이블에, 나는 이해하지 못하는 문제가있을 것 같다? 이 특별한 경우에 무엇이 잘못 되었습니까? 마지막으로 어떻게 수정합니까?

편집 :

home.drives.201702050atl의 행 5에서 누락 된 세포가있다. 처음에는 이것이 문제 일 수 있다고 생각했습니다. 그러나 이것이 내가 두 번째 테이블을 포함시킨 이유입니다. 두 번째 표에는 누락 된 셀이 없습니다. 아직, 나는 같은 오류가 발생합니다. 첫 번째 테이블과 비슷하지만 원본 테이블에는 두 번째 테이블의 코딩 전체가 포함되지 않았습니다. 아래에서 찾으십시오.

> 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 
+0

코드를 단계별로 실행하고 생성 된 개체를 살펴보십시오. 그러면 체인이 끊어진 부분을 확인하고 해결책을 찾을 수 있습니다. – ottlngr

+0

[this] (http://stackoverflow.com/questions/26147558/arguments-imply-differing-number-of-rows-8-20)의 가능한 중복, [this] (http://stackoverflow.com/questions/30270946/인수 - 암시 - 다른 - 행 번호 2-4-3-5) 및 [this] (http://stackoverflow.com/questions/35814146/r-error-arguments-imply-differing- 행 수)? – zx8754

+0

필자는 한 줄 씩 나갔다가 5 행에서 오류가 발생했습니다.이 줄은 새 테이블을 만들려고합니다. 중복 코멘트에 관해서는, 당신이 인용 한 게시물이 "행 수가 다르다"라는 오류가 발생하더라도 그 빌드는 완전히 다릅니다. – DataProphets

답변

0

오류는 코드의 다섯 번째 줄부터 있습니다.

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 

다섯 번째 요소의 길이는 0입니다.이 오류는 다른 행 수의 데이터 프레임을 만든 결과입니다. 다섯 번째 요소를 제거하면 문제가 해결 될 수 있습니다.

+0

그건 내가 처음에 문제가 있다고 생각 했거든. 그러나 두 번째 테이블에는 누락 된 셀이 없으며 같은 오류가 발생합니다. 나는 두 번째 테이블에 대한 나의 설명을 더 철저히 했어야했다. 코딩의 전체 내용을 포함하도록 초기 게시물을 편집 할 것입니다. – DataProphets