Im sure this is simple but Im new to R (like 30 minutes new) and still scratching my head.
I have five columns. I would like to sort the data by a composite of column a and b (a is chromosome, b is locus) and then average the values over columns sample1,sample2 and sample3 to provide a text output.
So far I have the following but I think my means calculation is letting me down
#Import the data as a data frame
df = read.table("mydata.txt")
#Make sure its there
summary(df)
#Make sure data is sorted by chromosome and by locus.
df = df[order(df[[1]], df[[2]]), ]
#Take the control samples and average each row for three columns excluding the first two     columns- add the per row means to the data frame
dfmns <- rowMeans( df[ , c("sample1", "sample2", "sample3")] ) 
The sample data is as follows:
chr leftPos strand  JWA JWB JWC JWD OE33_F
chr1    100202137   +   2   0   1   0   0
chr1    100260304   -   141 62  75  55  20
chr1    100724039   -   0   1   0   0   0
I would like
chr      leftPos    strand  JWA JWB JWC JWD OE33_F   Means
chr1    100202137   +          2    0   1   0   0     0.6
chr1    100260304   -        141    62  75  55  20    70.6
chr1    100724039   -          0    1   0   0   0     0.2
I think the code falls over at the order function as perhaps Im not referencing the columns properly?
 
     
    