2015-11-10 41 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)))