我有两个数据帧。对这两个函数应用相同的dcast()函数会在输出中得到不同的结果。这两个数据集具有相同的结构,但大小不同。第一个有超过950行:

我应用的代码是:
trans_matrix_complete <- mod_attrib$transition_matrix
trans_matrix_complete[which(trans_matrix_complete$channel_from=="_3RDLIVE"),]
trans_matrix_complete <- rbind(trans_matrix_complete, df_dummy)
trans_matrix_complete$channel_to <- factor(trans_matrix_complete$channel_to,
levels = c(levels(trans_matrix_complete$channel_to)))
trans_matrix_complete <- dcast(trans_matrix_complete,
channel_from ~ channel_to,value.var = 'transition_probability')我得到的trans_matrix_complete输出如下:

有些东西不能正常工作,因为对于只有几行的较小数据帧,我得到了以下结果:

哪里
a)行号不同。我不确定为什么第一个案例中列出了两个点
b)以及尝试通过以下方式将行名分配给数据帧
row.names(trans_matrix_complete) <- trans_matrix_complete$channel_from不适用于大型数据帧,因为尽管存在row.names联系人,但数据帧的显示与第一张图像中的完全相同,没有为行指定名称。
对这种奇怪的行为有什么想法吗?
发布于 2019-06-27 00:30:11
我使用以下函数解决了从dcast()迁移到tidyverse包的spread()的问题:
trans_matrix_complete<-spread(trans_matrix_complete,channel_to,transition_probability)
通过应用spread()这两个数据帧,矩阵输出具有相同的格式,并且可以没有任何问题地接受行名。
所以我怀疑这一切都是因为dcast()和reshape2包不再被维护的事实
问候
https://stackoverflow.com/questions/56756158
复制相似问题