Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a .tsv file

I need to read a table that is a .tsv file in R.

enter image description here

test <- read.table(file='drug_info.tsv') # Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  #   line 1 did not have 10 elements test <- read.table(file='drug_info.tsv', ) # Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  #   line 1 did not have 10 elements scan("drug_info.tsv") # Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  #   scan() expected 'a real', got 'ChallengeName' scan(file = "drug_info.tsv") # Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :  #   scan() expected 'a real', got 'ChallengeName' 

How should I read it?

like image 835
Andrew Voronkov Avatar asked Oct 24 '15 19:10

Andrew Voronkov


People also ask

What program will open a TSV file?

You can open TSV files with a large number of applications, including Microsoft Excel (multiplatform) and OpenOffice Calc (multiplatform). You can upload TSV files to Google Sheets to view, edit, save, and convert the files.

How do I import a TSV file into Python?

The very simple way to read data from TSV File in Python is using split(). We can read a given TSV file and store its data into a list.


Video Answer


2 Answers

This should do it:

read.table(file = 'drug_info.tsv', sep = '\t', header = TRUE) 
like image 89
Robert Avatar answered Oct 05 '22 16:10

Robert


Using fread from the package data.table will read the data and will skip the error you are getting using read.table.

require(data.table)  data<-as.data.frame(fread("drug_info.tsv")) 
like image 38
TBhavnani Avatar answered Oct 05 '22 14:10

TBhavnani