Error saying duplicate row names are not allowed when trying to setup my data for the mlogit-package

0 votes

I am trying to setup my data for the mlogit-package in R, but somehow seem to run into trouble.

My data-frame is called choice2, and it looks like this:

id choice_id mode.ids choice weightloss adveffect inj tab infreq_1 infreq_3 cost
1        x1        A      0        3.5         0   1   0        1        0  550
1        x1        B      0       10.0         1   0   1        0        1   90
1        x1        C      1        0.0         0   0   0        0        0    0
1       x10        A      0        6.0         0   1   0        0        1   50
1       x10        B      0        3.5         1   0   1        1        0  165
1       x10        C      1        0.0         0   0   0        0        0    0
1       x11        A      0        2.0         1   1   0        0        1  165
1       x11        B      1        3.5         0   0   1        1        0   90
1       x11        C      0        0.0         0   0   0        0        0    0
1       x12        A      0       10.0         1   1   0        0        1  550

I setup my data for the mlogit-package in R by running the following command:

require(mlogit)
CLOGIT <- mlogit.data(choice2,
                  choice = "choice",
                  shape = c("long"),
                  id.var = "id",
                  alt.var = "mode.ids",
                  varying = 5:11,
                  chid.var = "choice_id",
)

However, this results in the following error-message:

Error in `row.names<-.data.frame`(`*tmp*`, value = c("x1.A", "x1.B", "x1.C",  : 
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘x1.A’, ‘x1.B’, ‘x1.C’, ‘x10.A’, ‘x10.B’, ‘x10.C’, ‘x11.A’, ‘x11.B’, ‘x11.C’, ‘x12.A’, ‘x12.B’, ‘x12.C’, ‘x13.A’, ‘x13.B’, ‘x13.C’, ‘x2.A’, ‘x2.B’, ‘x2.C’, ‘x3.A’, ‘x3.B’, ‘x3.C’, ‘x4.A’, ‘x4.B’, ‘x4.C’, ‘x5.A’, ‘x5.B’, ‘x5.C’, ‘x6.A’, ‘x6.B’, ‘x6.C’, ‘x7.A’, ‘x7.B’, ‘x7.C’, ‘x8.A’, ‘x8.B’, ‘x8.C’, ‘x9.A’, ‘x9.B’, ‘x9.C’
Nov 12, 2018 in Data Analytics by Ali
• 11,360 points
1,752 views

1 answer to this question.

0 votes

Take out the chid.var argument in your call to mlogit.data, and you won't receive the error.

answered Nov 12, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
1 answer

Error saying " cannot open the connection" when trying to install a package in R

Try install.packages(“package_name”, repos="http://cr ...READ MORE

answered Nov 26, 2018 in Data Analytics by Maverick
• 10,840 points
8,548 views
+1 vote
1 answer

"Error in eval(ei, envir) : object 'RDX2' not found" when trying to source the code in R

This is a very common issue that ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,840 points
4,661 views
0 votes
1 answer
0 votes
1 answer

": cannot open the connection" Error in R

There can be two reasons for this ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
4,630 views
+2 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
9,355 views
+1 vote
1 answer

What does “replacement has” Error mean?

This error occurs when one tries to ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 52,360 points
478 views
0 votes
1 answer

Errors saying "Error: unexpected '}' in "}"

This is a syntax error: Enclose your if ...READ MORE

answered Nov 8, 2018 in Data Analytics by Maverick
• 10,840 points
2,772 views
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
1,413 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP