I want to run the mlogit function on my discrete choice dataset. Below I have provided the data and the lines of R code utilizing the package mlogit that are producing the errors. I am getting an error when running the full dataset about the dimensions for mlogit.data. When running mlogit, I am getting an error around coercing the "choice" variable to a logical.
Here is a snapshot of the code and the structure to reproduce a subset of it in R.
structure(list(row_id = c("1a", "1b", "1c", "1d", "1e", "1g"), choice = structure(c(2L, 1L, 2L, 1L, 2L, 1L), .Label = c("1", "2"), class = "factor"), alt_var = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), meal_choice = structure(c(1L, 2L, 1L, 1L, 1L, 2L), .Label = c("1", "2"), class = "factor"), transport_choice = structure(c(1L, 2L, 1L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), packaging_source = structure(c(1L, 2L, 1L, 1L, 2L, 2L), .Label = c("1", "2"), class = "factor"), disposal_choice = structure(c(1L, 2L, 1L, 1L, 2L, 2L), .Label = c("1", "2"), class = "factor")), row.names = c(NA, -6L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x7fa6d980f8e0>)
mlogit.data(data = df, choice = "choice", shape = "long", alt.var = "alt_var", id.var = "row_id", drop.index = TRUE)
Error in `$<-.data.frame`(x, name, value) : replacement has 964 rows, data has 965
mlogit(choice ~ meal_choice + transport_choice + packaging_source + disposal_choice, df, reflevel = "car")
`Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index, :
impossible to coerce the choice variable to a logical`