R 重塑2:dcast页边距行为

R 重塑2:dcast页边距行为,r,casting,reshape2,melt,table-statistics,R,Casting,Reshape2,Melt,Table Statistics,我写这封信是为了寻求帮助,了解一种令我困惑的reforme2::dcast行为。当我运行以下四行时(示例数据集 “french_fries”随“Reforme2”包一起提供),我得到了三个不同长度的data.frames,但我希望它们除了排列的行和列之外是相同的: library('reshape2') ff_d <- melt(french_fries, id=1:4, na.rm=TRUE) # "french_fries" is included in the 'reshape2'

我写这封信是为了寻求帮助,了解一种令我困惑的reforme2::dcast行为。当我运行以下四行时(示例数据集 “french_fries”随“Reforme2”包一起提供),我得到了三个不同长度的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.
library('reformae2')

当前和预期结果的实际数据样本可能有助于说明您的需求,并帮助我们重现您的问题。我们确实有你的数据在我们面前!谢谢你的回复;我猜数据集有点太大,无法直接粘贴到问题中,但是输入数据集“french_fries”包含在“Reforme2”包中,因此代码应该是可运行的。我额外添加了一行来说明预期结果(data.frame'd')。当前和预期结果的实际数据样本可能有助于说明您的需求,并帮助我们重现您的问题。我们确实有你的数据在我们面前!谢谢你的回复;我猜数据集有点太大,无法直接粘贴到问题中,但是输入数据集“french_fries”包含在“Reforme2”包中,因此代码应该是可运行的。我额外添加了一行来说明所需的结果(data.frame'd')。