Re: [R] apply function across dataframe columns for non-exclusive groups

2015-10-21 Thread Jeff Newmiller
The calculation appears to be sum(a)/(sum(a)+sum(b)). library(dplyr) library(tidyr) result <- ( this_df %>% gather( group, truth, -c(a,b) ) %>% group_by( group, truth ) %>% summarise( calc = sum(a)/(sum(a)+sum(b)) ) %>% as.data.frame ) -

[R] apply function across dataframe columns for non-exclusive groups

2015-10-21 Thread Alexander Shenkin
Hello all, I've been banging my head over what must be a simple solution. I would like to apply a function across columns of a dataframe for rows grouped across different columns. These groups are not exclusive. See below for an example. Happy to use dplyr, data.table, or whatever. Any g