假设df
是一个包含许多列的数据表。我想按variable1
进行分组,并为f
中的所有变量汇总函数variables_f
的数据表,并使用g
汇总variables_g
<中的所有变量/ p>
答案 0 :(得分:1)
假设'variables_f'和'variables_g'是表示列名的vector
个字符串character
,我们按'variable1'分组,获取这些vector
的值list
mget
lapply
,循环显示f
,应用函数g
和c
,然后连接(df[, c(lapply(mget(variables_f), f),
lapply(mget(variables_g), g)), by = variable1]
)
set.seed(24)
df <- data.frame(variable1 = rep(LETTERS[1:5], each = 2),
matrix(sample(1:9, 10*20, replace=TRUE), ncol=20,
dimnames = list(NULL,
c(paste0('var_f', 1:10), paste0('var_g', 1:10)))))
setDT(df)
variables_f <- paste0("var_f", 1:10)
variables_g <- paste0("var_g", 1:10)
f <- function(x) mean(x)
g <- function(x) max(x)
deployer:
image: jenkins
volumes:
- "/mnt/jenkins:/var/jenkins_home"
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- "2375:2375"
- "8080:8080"
- "50000:50000"