I want to be able to collapse and sum values dependent on the gene name I have a table that looks like this: 

I want add together all the values for each gene for each column. For example, for LINC01128, it should read:
             ConN1   ConN2   ConN3   StN1   StN2   StN3
LINC01128 :    22      14      37     34     54     67 

My table is very long and this would need to be done for all the genes.
You can use dplyr, where df is your data.frame:

df %&gt;% group_by(gene) %&gt;% summarise_if(is.numeric, sum)


This will sum each column separately (assuming it is numeric), grouped by each gene. Any column that is not included in the group_by or is not numeric will be dropped at this stage.