我試圖在與內置n功能一個DF基本dplyr :: summarize_if:使用內置函數的n與summarize_if
###Seems like this should work
df %>% summarise_if(is.numeric, funs(n, mean, sd, min, max), na.rm = TRUE)
Error in summarise_impl(.data, dots) : `n()` does not take arguments
###Works fine without the n
df %>% summarise_if(is.numeric, funs(mean, sd, min, max), na.rm = TRUE)
A tibble: 1 x 104
我試過n()
和n(.)
(這當然不期望工作,不)。
任何祕密,我缺少的summarise_if
使用funs(n)
?
不幸的是,'N()'期待一個'data.frame',而函數中'玩意兒(...)'將被傳遞的載體。也許'長度'? (可能不是你想要的...你想單個'n'變量,我認爲...) – r2evans
謝謝@ r2evans,很棒的一點。唉,的確,我嘗試了一段時間,並且還計算了兩者的錯誤(長度表示它收到兩個參數)。 –
@BenjaminGowan - 你需要創建一個新的'length()'來處理(和忽略)其他參數 - 例如'len < - function(x,...)length(x)'。雖然它仍然會重複每個變量。 – thelatemail