Use excel's lookup function to bin data

When we count data, we often divide the data into several categories according to certain standards, and then count the frequency and proportion of each category of data. For example, we need to count the number of students in different grades.

What we get is the specific score of each student, the purpose is to count the number of students in different scores. In order to achieve this goal, we first divide the scores into designated score segments, and then count the number of people in each score segment. Before, I used a series of if statements to divide the data into bins. The disadvantages of this are: 1) The code is longer and error-prone; 2) The bellows logic cannot be reused after the change. The following is an introduction to how to achieve this goal through excel's own function lookup.

LOOKPU(lookup_value, lookup_vector, [result_vecor]),其中

  • lookup_value : required. Look up the value.
  • lookup_vector : required. An area that contains only one column or one row. The values ​​in lookup_vector must be arranged in ascending order, otherwise errors may occur.
  • result_vecor : Optional. An area containing only one row or one column. If omitted, the return value is returned in lookup_vector; if provided, its length must be consistent with the length of lookup_vector.

Here is an example to show you how to use lookup to bin data. The following table shows the test scores of a certain class and the rules for boxing. We can divide the scores into bins according to the rules through lookup.

 

We use  LOOKUP (B2,F:F,G:G) and LOOKUP (B2,F:F,H:H) to achieve the score according to the score and interval bellows. The results are as follows:

Guess you like

Origin blog.csdn.net/lz_peter/article/details/98878707