loops in R, finding the mean for one column depends on another column
===

So my test  data looks like this:

       structure(list(day = c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L
    ), Left = c(0.25, 0.33, 0, 0, 0.25, 0.33, 0.5, 0.33, 0.5, 0), 
        Left1 = c(NA, NA, 0, 0.5, 0.25, 0.33, 0.1, 0.33, 0.5, 0), 
        Middle = c(0, 0, 0.3, 0, 0.25, 0, 0.3, 0.33, 0, 0), Right = c(0.25, 
        0.33, 0.3, 0.5, 0.25, 0.33, 0.1, 0, 0, 0.25), Right1 = c(0.5, 
        0.33, 0.3, 0, 0, 0, 0, 0, 0, 0.75), Side = structure(c(2L, 
        2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("L", "R"), class = "factor")), .Names = c("day", 
    "Left", "Left1", "Middle", "Right", "Right1", "Side"), class = "data.frame", row.names = c(NA, 
    -10L))

or this:

    day Left Left1 Middle Right Right1 Side
    1   1 0.25    NA   0.00  0.25   0.50    R
    2   1 0.33    NA   0.00  0.33   0.33    R
    3   2 0.00  0.00   0.30  0.30   0.30    R
    4   2 0.00  0.50   0.00  0.50   0.00    R
    5   2 0.25  0.25   0.25  0.25   0.00    L
    6   3 0.33  0.33   0.00  0.33   0.00    L


I would like to write a loop to find the standard error and average value for each day on the chosen side..     


The code might start like this.. I am stuck with the numbered points on how to write the code.. 


    td<-read.csv('test data.csv')
    IDs<-unique(td$day)
    for(i in 1:length(IDs)){
    day.i<-which(td$day==IDs[i])


1.Create 'if' statement to select which side was preferred

2. If $side ='L' then cbind($Left + $Left1) = left.i

3. If $side = 'R' then bind(Right + Right1) = right.i

4. For each day find mean and standard error (or a 5 number summary) of chosen side.. 
so maybe something like 'for day.i find mean(left.i or right.i) depending on td$side. 



I tried to get this going earlier but I did not enter the data correctly.. I think this is more understandable/workable.

Thank you for you help!
