I have a large gene expression data frame with duplicated genes that represents different samples (groups). For the the duplicated genes, I need to select only one row, based on the mean value between each duplicated of the same group (column).
Here is a small example of my dataframe:
GENES=c("7A5", "A1BG", "A1BG", "A1BG","AAAS","AAAS", "AFDS","AFDS","AFDS")
 Group1 = c(2.1471840, -0.9092227, -1.4875100, -2.79559765,  0.05143231, -1.25764808,  0.6104962,  0.09226673, -0.8037355)
 Group2 = c(-0.3709474,  1.4587290,  1.4545832, -0.27379895, -0.45116476,  1.56286706, -0.9225275, -0.54779659, -1.0586287)
 Group3 = c(-1.1321667, -1.3051079, -0.9658358, -0.05914144, -0.20133056,  0.03029207,  1.0015907,  1.18145151,  0.5360956)
 Group4 = c(0.6824169,  0.1645328,  2.6276603,  1.11739548, -1.13592005, -0.12666909, -0.4667365, -0.80153098, -1.1085319)
 Group5 = c(1.1014914, -1.4461279,  1.0965057, -1.58379531, -0.12457328,  0.59232328,  0.2319656,  0.46981373, -0.4540254)
df=data.frame(GENES,Group1,Group2,Group3,Group4,Group5)
> df
  GENES      Group1     Group2      Group3     Group4     Group5
1   7A5  2.14718400 -0.3709474 -1.13216670  0.6824169  1.1014914
2  A1BG -0.90922270  1.4587290 -1.30510790  0.1645328 -1.4461279
3  A1BG -1.48751000  1.4545832 -0.96583580  2.6276603  1.0965057
4  A1BG -2.79559765 -0.2737989 -0.05914144  1.1173955 -1.5837953
5  AAAS  0.05143231 -0.4511648 -0.20133056 -1.1359200 -0.1245733
6  AAAS -1.25764808  1.5628671  0.03029207 -0.1266691  0.5923233
7  AFDS  0.61049620 -0.9225275  1.00159070 -0.4667365  0.2319656
8  AFDS  0.09226673 -0.5477966  1.18145151 -0.8015310  0.4698137
9  AFDS -0.80373550 -1.0586287  0.53609560 -1.1085319 -0.4540254
For exemple, the gene A1BG have 3 duplicates. So, for A1BG new value of Group1 I need to:
mean(df[2,2],df[3,2],df[4,2])
For Group2, i need to:
mean(df[2,3],df[3,3],df[4,3])
And do the same for all the groups.
 
     
    