Просто из любопытства, есть ли способ воссоздать вывод summary
, используя data.table
вместо dplyr
?
dt1 <- data.table(
uid=c("A00111", "A00112","A00113","A00211","A00212","A00213","A00214","A00311","A00312"),
area=c("A001", "A001","A001","A002","A002","A002","A002","A003","A003"),
price=c(325147,NA,596020,257409,241206,248371,261076,595218,596678),
type=c("Type1","Type2","Type3","Type2","Type3","Type2","Type2","Type2","Type3"))
summary <- dt1 %>% group_by(area) %>% summarise(
Total_Number = length(uid),
Total_Number_Check = unique(length(uid)),
Number_of_Type_1 = length(uid[type=="Type1"]),
Mean_Price_Type_1 = mean(price[type=="Type1"],na.rm = TRUE),
Number_of_Type_2 = length(uid[type=="Type2"]),
Mean_Price_Type_2 = mean(price[type=="Type2"],na.rm = TRUE),
Number_of_Type_3 = length(uid[type=="Type3"]),
Mean_Price_Type_3 = mean(price[type=="Type3"],na.rm = TRUE))