I have a large matrix num [1:62410, 1:48010]
I want this in a long format data.table
e.g.
Var1 Var2 value
1: 1 1 -4227.786
2: 2 1 -4211.908
3: 3 1 -4197.034
4: 4 1 -4183.645
5: 5 1 -4171.692
6: 6 1 -4161.634
minimal example
m = matrix(1:5, nrow = 1000, ncol = 1000)
x = data.table(reshape2::melt(m))
ideally I'd want the columns names x, y and value at the same time.
Previously I've been using data.table(melt(mymatrix))
.
But judging by the warnings that reshape2::melt
is deprecated, this is probably not optimal in terms of speed, what would be the best "data.table" way of solving this?
the following do not answer my question: Fast melted data.table operations Proper/fastest way to reshape a data.table
Other answers refer to the deprecated reshape2
package