0

I tried to open an excel file and do regression analysis but there was some error. I have not used this program than just a few times so i writen the commands here if somebody would be so nice to help me..

> library(RODBC)
> library(mlogit)
Loading required package: Formula
Loading required package: statmod
Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'

The following object(s) are masked from 'package:base':

    as.Date

Loading required package: maxLik
Loading required package: miscTools
> z<-odbcConnectExcel("C:\\2008 Racedata.xls")
> y<-sqlFetch(z,"Sheet1")
> x<-mlogit.data(y,choice="winner",shape="long",id.var="datekey",alt.var="horseno")
Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.8", "1.11", "1.6",  : 
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘10.2’, ‘10.4’, ‘10.8’, ‘100.7’, ‘101.1
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 2
    can you please post at the very least the results of `str(y)`? Can you tell us if similar analyses of different data sets have worked for you in the past? Please read http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and consider editing your post accordingly ... – Ben Bolker Aug 25 '11 at 17:12
  • I don't think this is a file opening error. Your error occurs in `mlogit.data`, which is **very** particular about the data format. That said, the `mlogit` package has **comprehensive** manual and vignette that describes what the data should look like. Compare your data format to http://cran.r-project.org/web/packages/mlogit/mlogit.pdf – Andrie Aug 25 '11 at 17:58

1 Answers1

0

I do not know how the ODBC driver assigns row.names when the data gets imported. I would hope that it wouldn't allow for duplicates, since R does not allow duplicate row names in the same dataframe. It looks like the row.names are getting assigned by whatever is in the first column.

To guarantee that a data frame has unique row names, you can execute the following:

row.names(y) <- 1:length(y[,1])
adamleerich
  • 5,741
  • 2
  • 18
  • 20