How to calculate overall standard deviation from standard deviation of sub-periods? If I have the mean, s.d., median and count for sample A, and the same for sample B, can I throw away the samples, and calculate exactly mean, median and s.d. for the combination? Well the mean is easy.
Here is the question in R code:
a=c(1,2,3,4,5)
b=c(2,2,3,4,4,5)
c=c(a,b)
m=( (length(a)*mean(a)) + (length(b)*mean(b)) ) / (length(a)+length(b))
print(mean(c) == m) #TRUE
s= ???
print(sd(c) == s)
d= ???
print(median(c) == d)

I tried a few things for s.d. but failed; I had no idea for the median.
(For s.d. the closest I got was var(a)*(length(a)-1), doing the same for b, then dividing the sum by length(a)+length(b)-1. That gives 1.733 compared to var(c) of 1.7636.)
As a practical example, if I'm collecting stock ticks, I calculate mean, median and sd for each 1 minute period. Can I then use those 1 minute bars to make the same data for the 5 minute bars, and use the 5 minute bar data to make the hourly bars, and so on? Or, if I want to know the s.d. for weekly bars do I need to keep the ticks and load a full weeks worth of ticks in memory?
(Yes, I realize I could get a good enough approximation of the weekly answer by treating my minute bars as ticks, but I wanted to confirm my hunch that an exact answer is impossible once I've thrown away the ticks.)
UPDATE: given that I was wrong and getting the s.d. is possible (see answers below), I'm now wondering if the median is also not impossible? E.g. how about if I also knew the median absolute deviation (mad() in R) for each sub-period?
 A: I'm too lazy to write out the math but I already have some R code that reconstructs the variance of the combined datasets given the variances and means from the subsets.
dat1 <- rnorm(20)
dat2 <- rnorm(10)
dat <- c(dat1, dat2)

n <- length(dat)
n1 <- length(dat1)
n2 <- length(dat2)

m1 <- mean(dat1)
m2 <- mean(dat2)
m <- mean(dat)  # We know we could reconstruct this

# Only a function of the means and variances and lengths of the subsets
((n2-1)/(n-1))*var(dat2) + n2*(m2-m)^2/(n-1) + ((n1-1)/(n-1))*var(dat1) + n1*(m1-m)^2/(n-1)
# But it matches the variance of the combined data
var(dat)

I'll note that the reason your attempt doesn't work is that you fail to account for idea that the combined variance is calculated with the combined mean whereas the variances for the subsets calculated with their respective means.  The piece that I add in are the differences between the subset means and the combined mean scaled appropriately.
A: Take a look at the formulas for calculating the various sums of squares and mean squares for a one-way ANOVA.  What you want to do is just running ANOVA backwards.
A: Darren,
There are some 'running' algorithms for fast medians which use binning. I looked at a few in the past but have nothing ready-made I can point you to. This thread at stackoverflow maybe be useful.
A: To calculate the combined/composite median, you need all the individual measurements. Sorry, that's the only way to do it.
But it is possible to correctly calculate the combined/composite standard deviation without having all the individual measurements. You need three numbers for each sub-period: the mean of the measurements taken in that sub-period, the standard deviation of the measurements taken in that sub-period, and the number of measurements which were taken during that sub-period. This web page describes how you can then correctly calculate the standard deviation of the whole dataset; it includes source code in Perl do do it: 
http://www.burtonsys.com/climate/composite_standard_deviations.html
