Hi, Bonnie. I have a couple of comments about this.
First comment: if I assume that a bedtime less than 12 really means a late bedtime, I can get your average values just by adding in 24 at the appropriate places and modding it out at the end:
> zzz <- sleep
> zzz$bedtime <- ifelse(sleep$bedtime <= 12, sleep$bedtime + 24, sleep$bedtime)
> zzz
5 265 24.7
6 265 25.3
7 327 23.6
8 327 24.5
9 327 22.9
10 327 25.1
> zzzAve <- by(zzz$bedtime, zzz$
person.id, mean, na.rm=TRUE) %% 24
> zzzAve
zzz$
person.id: 117
[1] 22.35
------------------------------------------------------------------------
zzz$
person.id: 208
[1] NaN
------------------------------------------------------------------------
zzz$
person.id: 265
[1] 1
------------------------------------------------------------------------
zzz$
person.id: 327
[1] 0.025
Even if this is true, it probably doesn't help you, as you seem to have solved the problem, but I thought it was interesting.
Second comment: I don't understand your sd values. For person 117, for instance, you have:
sd = 0.22345815
But the bedtimes for person 117 are:
23.2
21.5
(with the NA removed). The mean for these two values is:
22.35
If I calculate the sample sd from what I understand to be the definition, I get:
> sqrt((23.2 - 22.35)^2 + (21.5 - 22.35)^2 / (2 - 1))
[1] 1.202082
I am evidently still confused about the procedure. What am I missing?
-- Mike