Read and explore dat files through R

Asked

Viewed 510 times

0

Guys I have a dat file: "dadodat"

How do I open it on the R and exploit it?

  • 2

    A . dat file can be anything, I think it’s the most generic format there is. If it is text with a table, just check what the file format is and use the table reading functions (read.table and the like). If it is text with other styles (xml type) or binary, it only makes sense if you know which is the source and there is a package for R that reads this.

  • Open the file with the Notepad and paste the first lines or an image. So it will be easier to try to help you

1 answer

1


Translating and Adapting the Answer from here.

First:

As a file .dat can store any kind of data, before importing it for the first time it is useful to use readLines to read the first lines of the file, so that you can identify what is the header of the data, what is actually the data:

readLines("http://www.nilu.no/projects/ccc/onlinedata/ozone/CZ03_2009.dat", 
          n=10)
# [1] "Ozone data from CZ03 2009"   "Local time: GMT + 0"        
# [3] ""                            "Date        Hour      Value"
# [5] "01.01.2009 00:00       34.3" "01.01.2009 01:00       31.9"
# [7] "01.01.2009 02:00       29.9" "01.01.2009 03:00       28.5"
# [9] "01.01.2009 04:00       32.9" "01.01.2009 05:00       20.5"

from this data set, it is possible to identify that the data actually start from the 4th row and are in table format. So just do:

Rapid Response:

read.table("http://www.nilu.no/projects/ccc/onlinedata/ozone/CZ03_2009.dat", 
           header=TRUE, skip=3)

If the data was not in table format, you could use another function to import, such as one of the generic functions of read.?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.