Splitting data array into sub arrays

조회 수: 3(최근 30일)
Francis Chabot
Francis Chabot 2021년 1월 19일
댓글: Francis Chabot 2021년 2월 4일
Hi, I want to split the data of an array by the first 2 numbers of each data. This is to split firms by the first 2 digit of their SIC codes.
Example: 3301 would be in the sub array 33 which would represent a sector.
Any suggestions would be helpful.
  댓글 수: 2
Francis Chabot
Francis Chabot 2021년 1월 20일
Thanks for the help.
The format are four digits numbers that needs to be classified by the first two numbers.
Example : 3301, 4502, 3306, 4602, 4510...
Both numbers that starts with 33 and 45 would be classified into the same sub array so I would then be able to easily compute the median of each sub array.
Speaking of scale there's about 100 sub array possible on about 20 000 firms.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb 2021년 1월 20일
>> SIC=[3301, 4502, 3306, 4602, 4510].';
>> splitapply(@median,SIC,findgroups(fix(SIC/100)))
ans =
NB: The use of mod above was in error, dunno how I came up with that, but as long as they're all four-digit codes, the above should be about as easy as it gets.
  댓글 수: 7
Francis Chabot
Francis Chabot 2021년 2월 4일
I forgot change the 'SIC' to 'Industry' but finally figured it out.
Best regards,

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by