1
$\begingroup$

I have a table that looks like this: enter image description here

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.

$\endgroup$
1
  • 1
    $\begingroup$ apply(table,1,sum) $\endgroup$ – user2974951 Oct 3 '18 at 10:41
0
$\begingroup$

You can use dplyr, where df is your data.frame:

df %>% group_by(gene) %>% 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.

$\endgroup$
0
$\begingroup$
data = aggregate(data,
                by = list(gene),
                FUN = sum)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.