[R] r: RODBC QUESTION
Clark Allan
Allan at STATS.uct.ac.za
Sat Dec 31 11:08:58 CET 2005
hello all
i have a quick question. i have been using the RODBC library (trying to
read Excel data
into R but i am doing this by using Rexcel. this is probably not the
correct forum -
sorry for this).
my code is shown below:
Sub A()
'start the connection to R
Call RInterface.StartRServer
RInterface.RRun "library(RODBC)"
RInterface.RRun "A = odbcConnectExcel('c:/TRY.xls')"
RInterface.RRun "q1 = sqlFetch(A, 'Sheet1')"
RInterface.RRun "odbcClose (A)"
Worksheets("out").Activate
Call RInterface.GetArray("q1", Range("A1"))
Call RInterface.StopRServer
End Sub
i have included four examples below. on the left hand side we have the
data as it appears
in Excel and on the right hand side we have the output from the code
(outputted to the
'out' sheet in excel). in the first example the code works while in the
other three
exampl0es it does not. ('a' is some character) when i use the commands
in r directly everything works correctly (ie missing values are treated
as NA - <characters is treated similarly>)
can anyone show me how to solve this!
ANOTHER QUESTION: am i allowed to have numeric and character values in
the same column when importing from Excel to R? (seems like i cant)
thanking you in advance!
wishing you all a happy new year (in advance)
/
allan
Y X1 X2 1 6 3
1 6 3 2 6 2
2 6 2 3 5 2
3 5 2
Y X1 X2 0
1 6 3
2 6 2
3 a 2
Y X1 X2 0
1 6 3
2 6 2
3 a 2
Y X1 X2 0
1 3
2 6 2
3 5 2
More information about the R-help
mailing list