我有一个带有数字变量(“数字”)和几个因子变量(因子 0 和 1(FALSE,TRUE)或 0 到 4(病理状态))的数据框。我想总结每个组(0 到 1、0 到 4)的“数字”的中位数和 IQR。
有没有办法将此函数应用于数据集中的每个因子列,而不必逐个键入一个变量?
`library(dplyr)
group_by(df, othervariable) %>%
summarise(
count = n(),
median = median(numeric, na.rm = TRUE),
IQR = IQR(numeric, na.rm = TRUE)
)`
输出:
othevariable count median IQR
<dbl> <int> <dbl> <dbl>
1 0 100 2.46 2.65
2 1 207 3.88 5.86