Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading PSV (pipe-separated) file or string

I have just received a data file, whose extension is "*.psv". After doing a bit of research, I don't know how to open it R.

like image 233
Duy Bui Avatar asked Mar 10 '15 14:03

Duy Bui


People also ask

Can CSV files be pipe delimited?

If your csv file consists of either pipe/comma separated data then you can go with pipe/comma as delimiter else if it a combined of comma and pipes.

How do I read a CSV file in a different separator?

Adding "sep=;" or "sep=," to the CSV file Here are the steps you should follow: Open your CSV using a text editor. Skip a line at the top, and add sep=; if the separator used in the CSV is a semicolon (;), or sep=, if the separator is a comma (,). Save, and re-open the file.

How do I open a CSV file in pipe delimited?

Launch Microsoft Excel, go to File > Open > change “All Excel Files” (to the right of the “File name”) to “All Files,” and find the pipe-delimited file you have just downloaded. Hit “Open” and Excel's “Text Import Wizard” will launch.


1 Answers

We could use read.table to read *.psv file.

read.table("myfile.psv", sep = "|", header = FALSE, stringsAsFactors = FALSE)

There might be many different representations of psv file, but when it comes to data mining, I think it might be more about "pipe separated" file. The data in the file is separated by "|"

like image 94
Duy Bui Avatar answered Sep 28 '22 18:09

Duy Bui