Skip to content
Prev 132458 / 398506 Next

median of binned values

Martin Tomko wrote:
Retrieve the numeric value rather than the category name as follows:

with(df, freq[median(rep(as.numeric(binname), freq))])
[1] 10000

  To do essentially the same thing with a vector:

myvec <- c(1,10,100,1000,10000)

myvec[median(rep(1:length(myvec), myvec))]
[1] 10000

  I'm sure I cannot explain levels() and rep() any better than the help
pages for those functions.