How to read a table missing or poorly configured elements?

Asked

Viewed 648 times

5

Suppose a text table like the following:

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

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

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 get around this problem?

1 answer

5


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.