gpt4 book ai didi

r - mlogit.data() 错误 : Assigned data `ids` must be compatible with existing data

转载 作者:行者123 更新时间:2023-12-03 14:15:08 26 4
gpt4 key购买 nike

我一直在努力解决这个问题,但我根本找不到任何解决问题的方法。希望这里有人可以提供帮助。

我正在尝试为具有以下结构的某些数据创建个人选择矩阵:

# A tibble: 2,152 x 32
age choice canton lr_s dist_svp dist_fdp dist_bdp dist_cvp dist_glp dist_sp
<dbl> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 39 sp GE 3 49 25 25 4 16 1
2 67 sp ZH 0 100 49 64 4 25 0
3 42 svp ZH 7 4 4 1 36 4 36

dist_gps pid_svp pid_fdp pid_bdp pid_cvp pid_glp pid_sp pid_gps french italian
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0 0 0 0 0 0 0 1 1 0
2 9 0 0 0 0 0 1 0 0 0
3 36 0 0 0 0 0 1 0 0 0

现在,我需要创建一个个人选择矩阵,其中包含列中 dist_*/pid_* 指示的 7 个备选方案。

根据我的理解,这应该使用以下代码:
work.pc <- mlogit.data(work,
varying = c(5:11, 12:18),
choice = "choice",
shape = "wide",
sep = "_")

但是,当我运行此代码时,我收到以下错误消息和一些警告消息:
Error: Assigned data `ids` must be compatible with existing data.
x Existing data has 15064 rows.
x Assigned data has 2152 rows.
ℹ Only vectors of size 1 are recycled.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning messages:
1: Setting row names on a tibble is deprecated.
2: Setting row names on a tibble is deprecated.
3: Setting row names on a tibble is deprecated.
4: Setting row names on a tibble is deprecated.
5: Setting row names on a tibble is deprecated.
6: Setting row names on a tibble is deprecated.
7: Setting row names on a tibble is deprecated.

这里有什么问题?我很感激任何帮助!我什么都试过了。

最佳答案

问题已解决:tibble“工作”必须转换为数据帧。
使用后

work <- as.data.frame(work)
代码正常运行,即消除了错误消息。

关于r - mlogit.data() 错误 : Assigned data `ids` must be compatible with existing data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61539386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com