Why does data.table not make the data.table out of the table, although data.frame?

I have the following data and code:

mydf grp categ condition value 1 AXP 2 2 BXP 5 3 AYP 9 4 BYP 6 5 AXQ 4 6 BXQ 5 7 AYQ 8 8 BYQ 2 > > mydf = structure(list(grp = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("A", "B"), class = "factor"), categ = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L), .Label = c("X", "Y"), class = "factor"), condition = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("P", "Q"), class = "factor"), value = c(2, 5, 9, 6, 4, 5, 8, 2 )), .Names = c("grp", "categ", "condition", "value"), out.attrs = structure(list( dim = structure(c(2L, 2L, 2L), .Names = c("grp", "categ", "condition")), dimnames = structure(list(grp = c("grp=A", "grp=B"), categ = c("categ=X", "categ=Y"), condition = c("condition=P", "condition=Q")), .Names = c("grp", "categ", "condition"))), .Names = c("dim", "dimnames")), row.names = c(NA, -8L), class = "data.frame") 

However, after working for data.frame, but not for data.table:

 > data.frame(with(mydf, table(grp, categ, condition))) grp categ condition Freq 1 AXP 1 2 BXP 1 3 AYP 1 4 BYP 1 5 AXQ 1 6 BXQ 1 7 AYQ 1 8 BYQ 1 > > data.table(with(mydf, table(grp, categ, condition))) V1 1: 1 2: 1 3: 1 4: 1 5: 1 6: 1 7: 1 8: 1 > 

Am I making some kind of mistake here or do I need to fix the data.table command to get other variables? It is very unlikely that there is a mistake. With 2 variables, it works correctly:

 > data.table(with(mydf, table(grp, categ))) categ grp N 1: AX 2 2: BX 2 3: AY 2 4: BY 2 > > > data.frame(with(mydf, table(grp, categ))) grp categ Freq 1 AX 2 2 BX 2 3 AY 2 4 BY 2 

Thank you for your help.

+6
source share
1 answer

Fixed in commit # 1760 data.table v1.9.5. Closes # 1043 .

+1
source

Source: https://habr.com/ru/post/982434/


All Articles