简体   繁体   English

R项目文件打开问题

[英]R-project file opening problem

I tried to open an excel file and do regression analysis but there was some error. 我试图打开一个excel文件并进行回归分析,但是出现了一些错误。 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

I do not know how the ODBC driver assigns row.names when the data gets imported. 我不知道导入数据时ODBC驱动程序如何分配row.names I would hope that it wouldn't allow for duplicates, since R does not allow duplicate row names in the same dataframe. 我希望它不允许重复,因为R不允许在同一数据框中重复行名。 It looks like the row.names are getting assigned by whatever is in the first column. 看起来row.names由第一列中的任何内容分配。

To guarantee that a data frame has unique row names, you can execute the following: 为了保证数据框具有唯一的行名,可以执行以下操作:

row.names(y) <- 1:length(y[,1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM