mlogit不允许重复的"row.names" [英] mlogit duplicate 'row.names' are not allowed
问题描述
R的新手,并想使用mlogit
功能.
New to R and want to use mlogit
function.
但是将我的数据放入数据框并运行后
However after putting my data into a data frame and run
x <- mlogit.data(mlogit, choice="PlacedN", shape="long", alt.var="RaceID")
我得到duplicate 'row.names' are not allowed
如果需要,我可以上传我的文件,我花了几天的时间尝试使其生效,因此我们将不胜感激
I can upload my file if needed I've spent days trying to get this to work, so any help will be appreciated
推荐答案
您可能希望将"RaceID"
而不是alt.var
放入alt.levels
自变量中.在mlogit.data
帮助文件中:
You may want to put "RaceID"
into the alt.levels
argument instead of alt.var
. From the mlogit.data
help file:
alt.levels
替代项的名称:如果为null,则对于宽data.frame,将根据变量名称和选择变量(两者应相同)进行猜测;对于长data.frame,则根据变量进行猜测. alt.var参数.
the name of the alternatives: if null, for a wide data.frame, they are guessed from the variable names and the choice variable (both should be the same), for a long data.frame, they are guessed from the alt.var argument.
尝试一下.
library(mlogit)
m <- read.csv("mlogit.csv")
mlogd <- mlogit.data(m, choice="PlacedN", shape="long", alt.levels="RaceID")
head(mlogd)
# RaceID PlacedN RSP TrA JoA aDS bDS mDS aDH bDH mDH LDH MR eMR
# 1.RaceID 20119552 TRUE 3.00 13 12 0 0 0 0 0 0 0 0 131
# 2.RaceID 20119552 FALSE 4.00 23 26 91 94 94 139 153 145 153 150 150
# 3.RaceID 20119552 FALSE 0.83 15 15 99 127 99 150 153 150 153 159 159
# 4.RaceID 20119552 FALSE 18.00 21 15 0 0 0 0 0 0 0 0 131
# 5.RaceID 20119552 FALSE 16.00 16 12 92 127 92 134 135 134 135 136 136
# 6.RaceID 20119617 TRUE 2.50 12 10 0 0 0 0 0 0 0 0 152
这篇关于mlogit不允许重复的"row.names"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!