2015-11-10 46 views
0

我有这个数据帧TT因素:你怎么挑dplyr汇总函数

structure(list(Hostname = structure(c(1L, 1L, 1L), .Label = "Server01", class = "factor"), 
    Date = structure(1:3, .Label = c("2015-10-01 08:15:00", "2015-10-01 08:30:00", 
    "2015-10-01 10:45:00"), class = "factor"), Cpubusy = c(35.2, 
    17.89, 22.04), Function = structure(c(1L, 1L, 1L), .Label = "Data Retriever", class = "factor")), .Names = c("Hostname", 
"Date", "Cpubusy", "Function"), class = "data.frame", row.names = c(NA, 
-3L)) 

我需要calcate平均,第95百分位,并创建一个表。

表应该看起来是这样的:

Server AVG 95th_Percentile Function 
Server01 10 30   Data Retriver 

我试过这样dplyr汇总函数:

cpu<-tt %>% group_by(Hostname) %>% summarise_(Mean = interp(~mean(Cpubusy, na.rm=FALSE)),Quantile= interp(~quantile(Cpubusy, prob=0.95,na.rm=FALSE)),tt$Function) 

不能插入函数数据为每个服务器。任何想法我可以做到这一点?

回答

0

我弄明白了,如果有人面临这个问题,你可以按多个字段进行分组。

这为我工作:

cpu<-tt %>% group_by(Hostname,Function) %>% summarise_(Mean = interp(~mean(Cpubusy, na.rm=FALSE)),Quantile= interp(~quantile(Cpubusy, prob=0.95,na.rm=FALSE)))