[R-SIG-Finance] Importing from Excel

MAB MichelBeck at sbcglobal.Net
Mon Feb 4 20:00:17 CET 2008


Hi!

I am trying to diff data imported from Excel.
I use the package xlsReadWrite.

After I load the following XL spreadsheet

C_Dates C_Price C_Prices_edit         C_Return_Raw        C_Return_edit
1   30405   29.40         29.40                 #N/A                 #N/A
2   30406   29.29         NaN                 -0.003               -0.003
3   30407      NA         29.29                    0                    0
(#N/A is a string in one case and the formula =NA() in another)

and try to diff the resulting object, I get:

Error in r[i1, , drop = FALSE] - r[-nrow(r):-(nrow(r) - lag + 1), , drop = 
FALSE] : 
        non-numeric argument to binary operator

I attempt to convert to numeric using as.matrix (or data.matrix),
but this converts the object to all characters.

I can then use as.numeric to get a vector and rebuild the matrix but this gets 
tedious.

Eventually the easiest seems to be to make sure each column in the spreadsheet
starts with a numeric, and replace it once the object is in R.

There is probably a better way.

Michel



More information about the R-SIG-Finance mailing list