reshape
とreshape2
ライブラリの両方を必要とするスクリプトがあります。私はこれが悪い習慣であることを知っていますが、plyr
(または私が使用している別のライブラリ)Vennerable
がロードされていると思います。私は多くの場所でreshape
個人的に使用しています。reshape2
reshape2
問題は、 byのマスキングが関数reshape
に問題を引き起こしていることですmelt
# Example data frame
df <- data.frame(id=c(1:5), a=c(rnorm(5)), b=c(rnorm(5)))
# With just reshape2, variable and value columns are labelled correctly
library(reshape2)
melt(df, measure.vars=c("a", "b"), variable.name="type", value.name="distance")
id type distance
1 1 a -2.0233666
2 2 a 0.4625188
3 3 a -2.8688127
4 4 a 0.8151644
5 5 a -0.4574464
6 1 b 1.3197784
7 2 b 1.6213146
8 3 b 1.3508913
9 4 b -1.6483839
10 5 b -1.1342157
# But my script also has reshape loaded
library(reshape)
Loading required package: plyr
Attaching package: ‘reshape’
The following object(s) are masked from ‘package:plyr’:
rename, round_any
The following object(s) are masked from ‘package:reshape2’:
colsplit, melt, recast
# When calling melt in this environment, variable and value columns stick to
# their default names
melt(df, measure.vars=c("a", "b"), variable.name="type", value.name="distance")
id variable value
1 1 a -2.0233666
2 2 a 0.4625188
3 3 a -2.8688127
4 4 a 0.8151644
5 5 a -0.4574464
6 1 b 1.3197784
7 2 b 1.6213146
8 3 b 1.3508913
9 4 b -1.6483839
10 5 b -1.1342157
特に使用してmelt
呼び出すことができると思いましたが、それでも同じ問題が発生します。reshape2
reshape2::melt
これを回避する簡単な方法はありますか?そうでない場合は、各メルトコールの直後に列名を手動で再ラベル付けする必要があります.