2014-07-21 2 views
0

이 그런 다음 "* .txt 인"기능 'read.table'및 오류

ID LBI RTI WDI FLA PSF FSF ZDF1 PROZD 
ar  ?,35.30,2.60, ?,42.4,24.2,47.1,69 
arn 1.23,27.00,3.59,122, 0.0,40.0,40.0,30 
be 1.24,26.50,2.90,121,16.0,20.7,29.7,72 
bi1 1.07,29.10,3.10,114,44.0, 2.6,26.3,68 
bi2 1.08,43.70,2.40,105,32.6, 5.8,10.7,42 
bie 1.39,29.50,2.78,126,14.0, 0.0,50.0,78 
bn 1.31,26.30,2.10,119,15.7,15.7,30.4,72 
bo 1.27,27.60,3.50,116,16.8,23.0,35.2,69 
by 1.11,32.60,2.90,113,15.8,15.8,15.0,57 

로 내 데이터를, 그것은 내가

r2 <- read.table('StoneFlakes.txt',header=TRUE,na.strings='?') 

오류를 명령 할 때 실패;

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : 
    line 1 did not have 9 elements 

누구나 나를 도와 줄 수 있습니까?

+1

@germcd : 그것은 아니다 '', ''하지만 처음 2 열의. –

+1

@JoshuaUlrich - 헤더에는','구분 기호가 전혀 없습니다. – thelatemail

+0

'readLines ("yourFile.txt")'의 처음 몇 줄을 게시하고 싶을 수도 있습니다. '문제가 어디에 있는지는 분명하지 않습니다. –

답변

3

사용

text <- readLines('StoneFlakes.txt') 
text <- gsub(",", " ", text) 
read.table(textConnection(text), header=TRUE, na.strings='?') 
    #insted of using textConnection you can also use 
read.table(text=text, header=TRUE, na.strings='?')