You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create a data.table when one vector is transposed doesn't respect the name defined by user #4124
This is a minor issue, but I didn't expect this behavior:
# Create some dummy data:
library(data.table)
a <- as.data.table(matrix(1:4, ncol = 4))
a[, V1 := "x"]
setnames(a, 2:4, letters[2:4])
# make a new data.table out of the first one, transposing one of the vectors:
b <- data.table(name = names(a)[2:4], value = t(a[, 2:4]))
# produces:
b
name value.V1
1: b 2
2: c 3
3: d 4
I didn't expect my defined name value would become value.V1.
I'm aware I could have done b <- melt(a, 1)[, 2:3] (and then rename the first column) to obtain the correct result.
Wrapping t(a[, 2:4) into extra call c() is enough as all is needed is to drop dimension attribute there. But agree, it should be handled better, as it is in data.frame case. It can be simplified to this:
Activity
jangorecki commentedon Apr 5, 2020
Wrapping
t(a[, 2:4)into extra callc()is enough as all is needed is to drop dimension attribute there. But agree, it should be handled better, as it is in data.frame case. It can be simplified to this:(textproc/R-data.table) Updated 1.16.4 to 1.18.4, Fix build against 4…
(textproc/R-data.table) Updated 1.16.4 to 1.18.4, Fix build against 4…