I have a .dat file of time series data for options so it includes trade date and expiration date, in addition to the price data for which I want to do timeseries analysis in R. I am new to R, so I have been following some of the examples online. in my attempt to upload the data as a data-frame, I tried the 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 it is expecting real but I need to enter the dates and the option ticker to make sense of the time series, so can someone give me some guidance on how I go about it.thx.
Scan requires that you specify the contents of the data; by default it assumes that you are just reading in numbers (which you aren't).
As per Joran's comment, read.csv (or read.table) is much more user friendly for reading in data frames from file.  Use that instead.
I'll reiterate that scan is a pretty low-level function and in almost every case you're better off using read.table or read.csv.
But to get scan to work on what I am inferring 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With