Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7065545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:58:10+00:00 2026-05-28T04:58:10+00:00

Here is my problem: How can I find the index of the histogram bin

  • 0

Here is my problem:

How can I find the index of the histogram bin in which a number falls?

In Matlab, the solution is easy. HISTC does the job:

[counts,bin] = histc(data,edges)

“bin” being what I am looking for.

But I am working in R, and the hist function of R doesn’t propose the functionnality. I think I could manage with some lines of code (using some things as min and <), but as I need to do it for many numbers, I would like to find a more elegant solution.

Since I am not very experienced in R, I hope there could exist a tricky solution, taking to the problem in another way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:58:10+00:00Added an answer on May 28, 2026 at 4:58 am

    The hist function will return the breakpoints between the bins if you do not already have them. You can then use the findInterval function to find which interval/bin each of your points falls into:

    > tmp <- hist(iris$Petal.Width)
    > findInterval(iris$Petal.Width, tmp$breaks)
      [1]  2  2  2  2  2  3  2  2  2  1  2  2  1  1  2  3  3  2  2  2  2  3  2  3  2
     [26]  2  3  2  2  2  2  3  1  2  2  2  2  1  2  2  2  2  2  4  3  2  2  2  2  2
     [51]  7  8  8  7  8  7  9  6  7  7  6  8  6  7  7  7  8  6  8  6 10  7  8  7  7
     [76]  7  7  9  8  6  6  6  7  9  8  9  8  7  7  7  7  7  7  6  7  7  7  7  6  7
    [101] 13 10 11 10 12 11  9 10 10 13 11 10 11 11 13 12 10 12 12  8 12 11 11 10 11
    [126] 10 10 10 11  9 10 11 12  8  7 12 13 10 10 11 13 12 10 12 13 12 10 11 12 10
    > tmp2 <- .Last.value
    > cbind( value=iris$Petal.Width, lower=tmp$breaks[tmp2], upper=tmp$breaks[tmp2+1])
           value lower upper
      [1,]   0.2   0.2   0.4
      [2,]   0.2   0.2   0.4
      [3,]   0.2   0.2   0.4
      [4,]   0.2   0.2   0.4
      [5,]   0.2   0.2   0.4
      [6,]   0.4   0.4   0.6
      [7,]   0.3   0.2   0.4
      [8,]   0.2   0.2   0.4
      [9,]   0.2   0.2   0.4
     [10,]   0.1   0.0   0.2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't seem to find solutions to this supposedly simple problem /bug, so here
Here is my problem : I have a list of messages which I can
I'm having a strange problem here, and I can't manage to find a good
I've been searching for hours for the solution to this problem but can't find
Having a problem here.... I can't seem to find a good way to 'add'
I have a problem here I can't solve. I have a database of houses
What can be the problem here?
Can't understand what is a problem here: I have got main.cpp file where I
Here is my problem. I have a chipmunk's rigid body (a soda can standing
HI Guys, Here I am having problem that How can I post an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.