I'm new to R and need some help. I have a huge data frame with different samples of patients. Each patient has 24 'chrom's. Each 'chrom' has 3 segments. Below is an example of patient 'A2461'. Below is an example of some of the data I have:
ID chrom loc.start loc.end num.mark seg.mean seg.sd seg.median seg.mad
1 A2461 1 61735 23342732 13103 0.0314 0.4757 0.0221 0.4811
2 A2461 1 23345569 54962669 17435 -0.0103 0.4807 -0.0292 0.4821
3 A2461 1 54963958 55075062 57 0.4841 0.4070 0.5201 0.3519
1 A2461 2 12784 17248573 13037 -0.0037 0.4643 -0.0053 0.4583
2 A2461 2 17248890 85480817 45819 -0.0331 0.4667 -0.0352 0.4635
3 A2461 2 85481399 89121495 1626 0.0153 0.4727 0.0000 0.4617
I currently have the total mean by using the following code:
seg_mean <- df$seg.mean
mean(seg_mean)
However, I would like to calculate the mean of 'seg.mean' for each chromosome with an output clarifying the patient ID and chrom. So perhaps something like...
ID chrom seg.mean
A2461 1 0.1684
A2461 2 -0.0072
Any help would be much appreciated! Thanks for reading.