Aggregating a dataframe dynamically with column names in strings from another dataframe

后端 未结 2 1755
遇见更好的自我
遇见更好的自我 2021-01-25 15:44

Ok, so I have a configuration dataframe that will specify, how I want to aggregate a few columns in another dataframe.

config frame:

conf <- rbind(            


        
2条回答
  •  -上瘾入骨i
    2021-01-25 16:10

    Stealing @Justin's suggestion here's what I ended up doing.

    aggregate(as.formula(paste("cnt", 
                               paste(conf[,1], collapse=" + "), 
                               sep=" ~ ")), data=dd, sum)
    

提交回复
热议问题