Search code examples
rdelimiterread.csv

Read a dsv file with custom delimiter into R


I have a dsv file with the custom delimiter |. I can easily read this into Stata by using the GUI to select a custom delimiter, but all the variants of read.csv that I've tried in R haven't worked.

Does anyone know how to how to import a dsv file into R with a custom delimiter?


Solution

  • You can use: read.table(filename,sep="|",header=TRUE). Given the file sample.csv with contents:

    a|b|c
    1|2|3
    

    The output looks like:

    read.table("sample.csv",sep='|',header=TRUE)
      a b c
    1 1 2 3