简体   繁体   中英

R histogram, find range of x-values by y-value (frequencies)

I have a list of values. With that I am actually not plotting a histogram, but returning a list of breaks and counts:

hist(loc$position, breaks=100000, plot=F)

Now I am trying to get the range of x-values, that are taken together into one bin. I am only interested in the bin with the maximum frequency. I therefore create

x <- hist(loc$position, breaks=100000, plot=F)

Now I am using that to return the middle of the bin as x-values with the max. frequency:

x$mids[which.max(list_histo$counts)]

But how do I get the full range of that one bin?

hist_data <- hist(loc$position, breaks=100000, plot=F)

c(hist_data$breaks[which.max(hist_data$counts)],
  hist_data$breaks[which.max(hist_data$counts)+1])

This way you will get a vector with the begin and end values of the bin with most elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM