1

我写信寻求帮助理解 reshape2::dcast 让我感到困惑的行为。当我运行以下四行时(示例数据集 'french_fries' 带有 'reshape2' 包),我得到三个不同长度的 data.frames,而我希望它们除了排列的行和列之外是相同的:

library('reshape2')
ff_d <- melt(french_fries, id=1:4, na.rm=TRUE) # "french_fries" is included in the 'reshape2' package
a = dcast(ff_d, treatment + subject ~ variable, mean, margins=T) # I think these data.frames are too long to paste directly into the question
b = dcast(ff_d, subject + treatment ~ variable, mean, margins=T)
d = merge(a, b, all = T) # I was expecting 'd' and 'a' (and 'b') to be identical.

公式左侧的变量是否被视为嵌套变量,因此我们只能在第一个变量的级别内获得第二个变量的边距?我将不胜感激任何见解,尤其是解释如何使用一个函数调用获得所有三种类型的边距,例如,treament=all by subject,subject=all by treatment,以及both=all。

非常感谢!

4

0 回答 0