2016-10-11 14 views
-1

많은 줄이있는 json 파일을 읽어야합니다.R의 텍스트 파일에서 빈 줄을 제거하는 방법은 무엇입니까?

파일 중 일부에서 파일을 R (jsonlite 사용)로 읽으려고 할 때 오류가 발생하는 빈 줄을 보았습니다.

R을 사용하여 빈 줄을 제거하려면 어떻게해야합니까? 다음과 같이) I는 readlines 메쏘드를 사용 끝에 그래서

mouse","trial_index":92,"time_elapsed":255348,"internal_node_id":"0.0-3.0-2.0-27.0","subject":"693","answer":1},{"rt":-1,"stimulus":"/study_assets/creactive/static/images/bird.jpeg","key_press":-1,"block":"two-back","condition":"target","trial_type":"single-stim-mouse","trial_index":93,"time_elapsed":257160,"internal_node_id":"0.0-3.0-2.0-28.0","subject":"693","answer":0},{"rt":407,"stimulus":"/study_assets/creactive/static/images/bird.jpeg","key_press":"mouse","block":"two-back","condition":"distractor","trial_type":"single-stim-mouse","trial_index":94,"time_elapsed":257871,"internal_node_id":"0.0-3.0-2.0-29.0","subject":"693","answer":0}] 

[{"rt":71,"key_press":"mouse","trial_type":"text","trial_index":0,"time_elapsed":74,"internal_node_id":"0.0-0.0","subject":"695"},{"rt":-1,"correct":false,"stimulus":"<DIV id=\"goNoGoFixationPoint\">+</DIV>","key_press":-1,"response":"fixation","trial_type":"categorize-mouse","trial_index":1,"time_elapsed":575,"internal_node_id":"0.0-1.0-0.0-0.0","subject":"695"} 
+2

을 read.table'여기

빈 라인 부분의 예()'하나는'blank.lines.skip = TRUE'을 설정할 수 있습니다 – jogo

+0

시도 할 때 다음과 같은 오류가 나타납니다 : {스캔 오류 (파일, 내용, nmax, sep, dec, quote, skip, nlines, na.strings, : 라인 2에는 111 개의 요소가 없습니다. –

+0

입력이 테이블이 아닙니다!'sep = ...'(결국'sep = 'μ '') 및'stringsAsFactors = FALSE' – jogo

답변

0

및 NCHAR (와 루프 :

x = JSONFILE 
readLines(x, skipNul= TRUE) 
for (i in 1:length(x)) { 
if(nchar(x[i]==0) { 
x <- x[-i] 
} 
} 
+0

1.'readLines()'의 결과는 어디에 두시겠습니까? 3. BTW : 하나의 표현식에 대해서만 중괄호가 필요하지 않습니다. – jogo

+0

데이터 프레임/파일 (dataframe <- readLines ...)에 넣었습니다. 2. R 문법에 익숙하지 않아서 좋습니다. 당신의 친절한 도움에 감사드립니다. –

관련 문제