R: read .tab files

11k views Asked by At

I am trying to import a .tab file into R but one of the rows has an unexpected number of elements which gives me an error.

data <- read.table(functions.tab, header = F, sep = "\t")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 397 did not have 4 elements

What is the best way around this so I don't lose any information? Is there a way to merge the overflow elements into the last column?

1

There are 1 answers

0
akrun On BEST ANSWER

We can use the fill argument in read.table for rows that have less number of elements to be filled by NA

data <- read.table(functions.tab, header = F, sep = "\t", fill = TRUE)