【发布时间】:2020-08-20 02:30:11
【问题描述】:
我正在尝试将数据与另一行进行 rbind。但我不断收到以下错误:
Error in `.rowNamesDF<-`(x, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘1’, ‘2’, ‘3’, ‘4’
我几乎可以肯定这与我的数据框在数据框内有一个数据框这一事实有关。
class(data)
[1] "dfidx_mlogit" "dfidx" "data.frame" "mlogit.data"
我的问题是,如果数据帧中嵌入了数据帧,我如何将数据与另一行或另一个类似维度的数据集进行绑定。或者如何将数据帧与嵌入的数据帧分开?
这就是我想要开始的工作:
#Row bind the dataset with itself.
new_data=rbind(data,data)
请注意,这是数据集的截断子集,其中包括数字和字符串变量,因此使用 as.numeric 对我不起作用,因为它是字符串值变量NA
这是数据:
data=structure(list(EDUC = c(4L, 4L, 4L, 4L), HEALTH = c(3L, 3L, 3L,
3L), idx = structure(list(chid = c(1L, 1L, 1L, 1L), unique_id = c(3000175513,
3000175513, 3000175513, 3000175513), alt = structure(1:4, .Label = c("Bicycle",
"Car", "Metro", "Walking"), class = "factor")), ids = c(1, 1,
2), row.names = c(NA, 4L), class = c("idx", "data.frame"))), row.names = c(NA,
4L), class = c("dfidx_mlogit", "dfidx", "data.frame", "mlogit.data"
), idx = structure(list(chid = c(1L, 1L, 1L, 1L), unique_id = c(3000175513,
3000175513, 3000175513, 3000175513), alt = structure(1:4, .Label = c("Bicycle",
"Car", "Metro", "Walking"), class = "factor")), ids = c(1, 1,
2), row.names = c(NA, 4L), class = c("idx", "data.frame")))
【问题讨论】: