Data type error with validation

I have a .dat file of time series data for options, so it includes the trading date and expiration date, in addition to the price data for which I want to do time series analysis in R. I am new to R, so I follow some examples on the internet. In an attempt to load data as a data frame, I tried scan (), but I get the following error:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, : scan() expected 'a real', got '2010-Aug-09,2011-Aug-19,C00026000,0.23985,5.53,0.999999,0.00712328' 

I understand that he expects the real, but I need to enter the dates and the option ticker in order to understand the time series, so that someone can give me some guidance on how I am talking about this. Thanks.

+7
source share
2 answers

Scanning requires you to specify the contents of the data; By default, it is assumed that you are simply reading numbers (which you are not).

According to Joran's comment, read.csv (or read.table ) is much more convenient for reading data from a file in a frame. Use this instead.

+9
source

I will repeat that scan is a rather low-level function, and in almost every case you are better off using read.table or read.csv .

But in order to get the scan to work on what I post is in your .dat file, you need to tell it (at least) what the field separator is and what the data types are. So something like:

 scan('temp.dat',sep=',',what=list('character','character','character','numeric','numeric','numeric','numeric')) 

would do the trick.

+9
source

All Articles