Mean of repeated lines

Asked

Viewed 48 times

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?

1 answer

6


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

library(dplyr)
dados %>% 
  group_by(Gene) %>% 
  summarise_all(mean)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.