Suppose you have measurements of 50001 gene samples, but some of them are duplicates. Taking the means of all those genes is trivial in R:

combined.samples <- aggregate(samples, by=list(aggregate$gene_id), FUN=mean)