Skip to content
Prev 69073 / 398502 Next

Calculate median from counts and values

On 5/3/05, David Finlayson <david.p.finlayson at gmail.com> wrote:
Is there supposed to be one row of values that apply to all
rows of counts or is there to be different rows of values for
different rows of counts?  Also in your example row 3 has
a different total than 1 or 2.  Is that right?

At any rate, I will assume that there is only one row of 
values and many rows of counts and that its not necessarily
true that counts sum to the same number in each row.
Then noting that  c(rep(4,1), rep(5,2), rep(6,3)) is the same
as rep(4:6, 1:3) is the same as, we have:

lapply(as.data.frame(t(counts)), rep, x = unlist(values))