将 n() 与 summarise_all 一起使用
Using n() with summarise_all
工作正常:
stats = c('mean', 'median', 'sd', 'max', 'min')
sumtable = iris %>% select(-Species) %>% summarise_all(.funs = stats)
无效:
stats = c('mean', 'median', 'sd', 'max', 'min', 'n')
sumtable = iris %>% select(-Species) %>% summarise_all(.funs = stats)
Error in summarise_impl(.data, dots) : `n()` does not take arguments
请指教
我想要这个功能是因为我想计算非缺失观察值。正如 Rohit 指出的那样,长度将计算所有行,包括丢失的 obs。所以我最后做的是这样的:
not.na = function(x) {sum(!is.na(x))}
stats = c('mean', 'median', 'sd', 'max', 'min', 'not.na')
sum.acs = acs %>% group_by(year) %>% summarise_all(.funs = stats)
工作正常:
stats = c('mean', 'median', 'sd', 'max', 'min')
sumtable = iris %>% select(-Species) %>% summarise_all(.funs = stats)
无效:
stats = c('mean', 'median', 'sd', 'max', 'min', 'n')
sumtable = iris %>% select(-Species) %>% summarise_all(.funs = stats)
Error in summarise_impl(.data, dots) : `n()` does not take arguments
请指教
我想要这个功能是因为我想计算非缺失观察值。正如 Rohit 指出的那样,长度将计算所有行,包括丢失的 obs。所以我最后做的是这样的:
not.na = function(x) {sum(!is.na(x))}
stats = c('mean', 'median', 'sd', 'max', 'min', 'not.na')
sum.acs = acs %>% group_by(year) %>% summarise_all(.funs = stats)