@@ -56,17 +56,22 @@ DT <- data.table(
5656)
5757
5858# rollup
59- rollup(DT , j = sum(value ), by = c(" color" ," year" ," status" )) # default id=FALSE
60- rollup(DT , j = sum(value ), by = c(" color" ," year" ," status" ), id = TRUE )
61- rollup(DT , j = lapply(.SD , sum ), by = c(" color" ," year" ," status" ), id = TRUE , .SDcols = " value" )
62- rollup(DT , j = c(list (count = .N ), lapply(.SD , sum )), by = c(" color" ," year" ," status" ), id = TRUE )
63- rollup(DT , j = sum(value ), by = c(" color" ," year" ," status" ),
64- label = list (color = " total" , year = as.Date(" 3000-01-01" ), status = factor (" total" ))) # specify label by variable name
65- rollup(DT , j = sum(value ), by = c(" color" ," year" ," status" ),
66- label = list (color = " total" , Date = as.Date(" 3000-01-01" ), factor = factor (" total" ))) # specify label by variable name and first element of class
67- rollup(DT , j = sum(value ), by = c(" color" ," year" ," status" ), label = " total" ) # label is character scalar so applies to color only
68- rollup(DT , j = .N , by = c(" color" ," year" ," status" ," value" ),
69- label = list (color = NA_character_ , year = as.Date(NA ), status = factor (NA ), value = NaN )) # label can be explicitly specified as NA or NaN
59+ by_vars = c(" color" , " year" , " status" )
60+ rollup(DT , j = sum(value ), by = by_vars ) # default id=FALSE
61+ rollup(DT , j = sum(value ), by = by_vars , id = TRUE )
62+ rollup(DT , j = lapply(.SD , sum ), by = by_vars , id = TRUE , .SDcols = " value" )
63+ rollup(DT , j = c(list (count = .N ), lapply(.SD , sum )), by = by_vars , id = TRUE )
64+ rollup(DT , j = sum(value ), by = by_vars ,
65+ # specify label by variable name
66+ label = list (color = " total" , year = as.Date(" 3000-01-01" ), status = factor (" total" )))
67+ rollup(DT , j = sum(value ), by = by_vars ,
68+ # specify label by variable name and first element of class
69+ label = list (color = " total" , Date = as.Date(" 3000-01-01" ), factor = factor (" total" )))
70+ # label is character scalar so applies to color only
71+ rollup(DT , j = sum(value ), by = by_vars , label = " total" )
72+ rollup(DT , j = .N , by = c(" color" , " year" , " status" , " value" ),
73+ # label can be explicitly specified as NA or NaN
74+ label = list (color = NA_character_ , year = as.Date(NA ), status = factor (NA ), value = NaN ))
7075
7176# cube
7277cube(DT , j = sum(value ), by = c(" color" ," year" ," status" ), id = TRUE )
0 commit comments