Average repeated lines

4

People,

I have a data.frame as follows

Gene              12h        10d         6w

Slc39a10         1.52      -6.72     -1.84
Slc39a10         1.52      -6.72     -1.84
Mfsd6           -0.15      0.672      0.26
Mfsd6           -2.55     -54.53     -23.75
Hecw2            2.13      2.71       1.92
Hecw2           -7.30     -4.34      -6.49

I wanted to take the average of these repeated values, but keep the line. It would look like this:

Gene              12h        10d         6w

Slc39a10         media     media      media

Mfsd6            media     media      media

Hecw2            media     media      media

Does anyone know how to solve it?

    
asked by anonymous 16.10.2018 / 20:31

1 answer

5

Using the dplyr package, you can use the group_by (which will group by genes) and summarise_all functions (which will summarize all columns according to a predetermined function).

library(dplyr)
dados %>% 
  group_by(Gene) %>% 
  summarise_all(mean)
    
16.10.2018 / 20:39