Skip to content
Prev 164734 / 398506 Next

how to convert factors to numbers

Hello, I am relatively new to using R.  I am using R version 2.8.0.  I have a
program that downloads stock data from Yahoo! Finance and stores it to a
text file on my hard drive.  The text file contains the date, opening price,
high price, low price, closing price, volume and adjusted price (i.e.,
adjusted for dividends and splits).  I want to read and manipulate the data
in R.  However, when I use read.table, it treats all of the data as
"factors" and I do not know how to treat the data as numbers:
QDate   OpenP   HighP    LowP  CloseP       Vol   AdjP
1 12/14/2006, 141.86, 143.24, 141.84, 143.12, 64755200, 138.34
Warning message:
In Ops.factor(spy[1, 5], spy[1, 2]) : - not meaningful for factors
As you can see, I cannot calculate the difference between the closing price
and the opening price, (much less compute averages, etc).  This is clearly a
"newbie" problem.  In my defense, I am using the book by Michael Crawley
(The R Book) as my teaching guide, but I cannot find the answer to this
question in that rather densely packed book.

Any help is appreciated.