1

私を混乱させている reshape2::dcast の振る舞いを理解する助けを求めるために書いています。次の 4 行を実行すると (サンプル データセット 'french_fries' は 'reshape2' パッケージに付属しています)、長さが異なる 3 つの 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.

式の左側の変数はネストされたものとして扱われているので、最初の変数のレベル内で 2 番目の変数のマージンしか得られませんか? 洞察、特に 1 つの関数呼び出しを使用して 3 種類のマージンすべてを取得する方法の説明に感謝します。

どうもありがとう!

4

0 に答える 0