dplyr: Subtracting values group-wise by group that matches given condition
问题 right now I'm refactoring an 'base'-based R script by using 'dplyr' instead. Basically, I want to group_by Gene and subtract the values group-wise by a group that matches a given condition. In this case, I want values of Gene == 'C' and subtract them from all others. Simplified data: x <- data.frame('gene' = c('A','A','A','B','B','B','C','C','C'), 'sample' = rep_len(c('wt','mut1','mut2'),3), 'value' = c(32.3,31,30.5,25,25.3,22.1,20.5,21.2,19.8)) gene sample value 1 A wt 32.3 2 A mut1 31.0 3 A