我正在写信请求帮助理解reshape2 :: dcast的行为让我感到困惑。当我运行以下四行时(示例数据集) ' french_fries'伴随着'重塑2'包),我得到三个不同长度的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,all = all。
非常感谢!