Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check how a file is delimited before reading into R

Tags:

import

r

I have a list of files (not made by me) that for some reason are all labelled (".csv") even though some are csv and some are tab delimited. So when I try read them in R, I would have to specify separator manually. Unless, someone knows if there is a way to check this before I get a mangled file read in.

like image 347
cianius Avatar asked Dec 07 '22 05:12

cianius


1 Answers

Should have put this in an answer...

The fread function in the package data.table makes an attempt to guess the correct separator. It's probably not perfect, but it will likely handle most simple cases.

like image 69
joran Avatar answered Jan 10 '23 07:01

joran