How can I count specific value in one column but based on another four columns
Show older comments
Hello,
How can I count specific value in one colum but based on another four columns
Example
Int_name Country # Milepost lighting condition Frequency
'"A" ST' '06223 15 D' 20.92 'C' ?
'"A" ST' '06223 15 D' 20.92 'C'
'"A" ST' '06145 20 D' 10.09 'A'
'"A" ST' '06145 20 D' 10.09 'A'
I need to count lighting condition: A or C frequency under same milepost under same country number under same Int_name
Like for "A" ST' , country number 06223 15 D and mile post 20.92 we have C ocuured 2 times. and so on for a large data.
Accepted Answer
More Answers (1)
Guillaume
on 25 Jul 2019
Assuming that your dara is in a table (it would be useful if the example used valid matlab syntax):
result = groupsummary(yourtable, {'int_Name', 'Country', 'Milepost'}, @numel, 'lighting_condition')
7 Comments
Shaden AbedRabbo
on 25 Jul 2019
Andrei Bobrov
on 25 Jul 2019
may be
.. @numel,'LIGHT')
Shaden AbedRabbo
on 25 Jul 2019
Variables need to be correctly spelled, including case.
result = groupsummary(updateddata1, {'int_desc', 'cnty_rte', 'milepost', 'LIGHT'}, @numel, 'LIGHT')
edit: I've just realised that what you want is an histogram, in that case 'LIGHT' is also a grouping variable, and the data variable that you choose to pass to numel is irrelevant.
Shaden AbedRabbo
on 25 Jul 2019
Guillaume
on 25 Jul 2019
I think I understand. In that case, the simplest is to go with findgroups, build the histogram of that, then redistribute the histogram in the table according to the table
group = findgroups(updateddata1(:, {'int_desc', 'cnty_rte', 'milepost', 'LIGHT'}));
count = accumarray(group, 1); %one of the many ways to get an histogram in matlab. See also histcounts
updateddata1.Frequency = count(group);
Shaden AbedRabbo
on 26 Jul 2019
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!.png)