Axel Leroix
2009-May-14 08:53 UTC
[R] Data extraction problem after importation using RODBC
Dear all,
I write this message because I have a problem in data importation. I hope that
you help me.
My data base is in an Excel spreasheet. I import this data base using the
following code:
library(RODBC)
db <- "C:/Users/Axel/Desktop/estimation/data.xls"
channel <- odbcConnectExcel(xls.file = db)
data <- sqlFetch(channel = channel, sqtable = "Feuil1")
data
odbcClose(channel)
Then I perform an lm regression using the following code:
reg1 <-lm(data$prod~data$pri+data$cli)
summary(reg1)
Then I try to perform a gls regression because I have a correlation problem. For
this I use the following code:
reg1gls <- gls(data$prod ~ data$pri + data$cli +
correlation=corAR1(form= ~data$Year), method='ML')
The problem is that after this gls regression, I have the fellowing error
message :
Error in eval(expr, envir, enclos) : 'Year' object is not find
When I relplace "Year" by 1 in the gls formula, I have a second error
message
Error in eval(expr, envir, enclos) : 'prod' object is not find
So I do not understand why R is able to extract variable from my data base with
an lm object but it is not able to do it with the gls object.
Do you have an idea about this problem?
Many thanks in advance.
[[alternative HTML version deleted]]
Dieter Menne
2009-May-14 13:32 UTC
[R] Data extraction problem after importation using RODBC
Axel Leroix wrote:> > > Then I perform an lm regression using the following code: > reg1 <-lm(data$prod~data$pri+data$cli) > summary(reg1) >Use reg1 <-lm(prod~pri+cli, data=data) instead. It is not necessary to call the data frame you read your stuff into "data", any more useful name, such as "ecg" or "delivery" will do. ? Then I try to perform a gls regression because I have a correlation problem. For this I use the following code: reg1gls <- gls(data$prod ~ data$pri + data$cli + correlation=corAR1(form= ~data$Year), method='ML') ? The problem is that after this gls regression, I have the fellowing error message : ? Error in?eval(expr, envir, enclos) :? 'Year' object is not find ? If you have problems, print str(data) << or whatever you want to call this Use the same form as above; check the documentation example. This has nothing to do with ODBC import, because your first example worked (I presume). Dieter -- View this message in context: http://www.nabble.com/Data-extraction-problem-after-importation-using-RODBC-tp23536716p23540678.html Sent from the R help mailing list archive at Nabble.com.