I am working with dc.forehead, which has 1014 rows and 33 columns. The rows are in triplicate, however, and I need to find the column mean for each set of three while keeping their categories.
ID Ancestry X400 X410 X420 etc.
140819 African 4.550 4.590 4.710
140819 African 4.310 4.290 4.440
140819 African 4.420 4.490 4.690
140822 African 4.190 4.040 3.630
140822 African 3.591 3.360 3.860
140822 African 3.890 3.860 3.420
140844 S. Asian 4.140 3.290 3.880
140844 S. Asian 3.370 3.720 4.150
140844 S. Asian 3.260 4.080 3.960
etc.
The result I would like would be like this:
ID Ancestry X400 X410 X420 etc.
140819 African 4.43 4.46 4.61
140822 African 3.89 3.75 3.63
140844 S. Asian 3.59 3.70 4.00
etc.
I've tried the following, but I lost the categories and it deleted one of the ID's and replaced it with #REF
aggregate(dc.forehead[,3:33], by = list(dc.forehead$ID), FUN = mean)
Any assistance would be really great: I'm new to R and in way over my head!
Thanks