How to read a table missing elements or misconfigured?

5

Suppose a table in the form of text like the following:

texto <- "a b c
e f
g h i"

When I use the read.table command, it gives the following error:

tabela <- read.table(text=texto)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 2 did not have 3 elements

How to work around this problem?

    
asked by anonymous 26.02.2014 / 17:31

1 answer

5

One way to solve the problem is to put the fill=TRUE argument in read.table :

tabela <- read.table(text=texto, fill=TRUE)
tabela
 V1 V2 V3
1  a  b  c
2  e  f   
3  g  h  i
    
26.02.2014 / 17:34