function - Read.table error in R -


i'm using r read text file , subsequently manipulate it. input file has 22 columns. first column looks :

name    length    c   d   e   f   g   h     k   l   m   n   p   q   r   s   t   v   w   y 

i using:

read.table("filename", stringsasfactors=false)  

to input file. when run same, warning:

error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :    line 2 did not have 23 elements 

not sure going wrong. i'm new r , appreciate help. i've tried make sure isn't repost, if is, please link me original.

assuming text file looks this:

name length c d e f g h k l m n p q r s t v w y  ape:ape_0001 242 15 0 1 12 10 18 2 27 9 43 7 2 8 3 5 25 15 24 3 12  ape:ape_0002 113 7 1 6 6 1 12 3 4 10 16 4 2 4 0 10 3 5 9 4 5  ape:ape_0004 305 24 2 5 8 9 25 4 36 12 43 8 11 14 2 12 20 21 27 9 12 

and called 'dat.txt' , stored in working directory, should work:

dat <- read.table("dat.txt", stringsasfactors=false, header=true) # give: dat           name length  c d  e  f  g h   k  l m  n  p q  r  s  t  v w  y 1 ape:ape_0001    242 15 0 1 12 10 18 2 27  9 43 7  2  8 3  5 25 15 24 3 12 2 ape:ape_0002    113  7 1 6  6  1 12 3  4 10 16 4  2  4 0 10  3  5  9 4  5 3 ape:ape_0004    305 24 2 5  8  9 25 4 36 12 43 8 11 14 2 12 20 21 27 9 12 

since doesn't appear working you, there might odd , invisible going on in text file, hidden characters, etc.

assuming text file isn't enormous, 1 workaround open new r script in rstudio type in

dat <- read.table(stringsasfactors=false, header=true, text = "") 

and copy , paste text in text file between "" in line above, without changes line breaks or formatting, , select , send console.

for example in comment this:

dat <- read.table(header=true, stringsasfactors=false, text = "name length c d e f g h k l m n p q r s t v w y  ape:ape_0001 242 15 0 1 12 10 18 2 27 9 43 7 2 8 3 5 25 15 24 3 12  ape:ape_0002 113 7 1 6 6 1 12 3 4 10 16 4 2 4 0 10 3 5 9 4 5  ape:ape_0004 305 24 2 5 8 9 25 4 36 12 43 8 11 14 2 12 20 21 27 9 12") 

if that's not practical or possible, post link text file in question (like this: http://temp-share.com/show/dpf3a6ohw deleted automatically after 45 days) others can have look.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -