Main Content

mergecats

범주를 categorical형 배열로 병합

설명

예제

B = mergecats(A,oldcats)A에 있는 둘 이상의 범주를 첫 번째 범주 oldcats(1)로 병합합니다. A의 값 중 oldcatsB에서 oldcats(1)이 됩니다.

예제

B = mergecats(A,oldcats,newcat)oldcats를 새로운 단일 범주 newcat으로 병합합니다. A의 값 중 oldcatsB에서 newcat이 됩니다.

예제

모두 축소

다양한 색을 포함하는 categorical형 배열을 만듭니다.

A = categorical({'red';'blue';'pink';'red';'blue';'red'})
A = 6x1 categorical
     red 
     blue 
     pink 
     red 
     blue 
     red 

A는 6×1 categorical형 배열입니다.

A의 범주를 표시합니다.

categories(A)
ans = 3x1 cell
    {'blue'}
    {'pink'}
    {'red' }

세 개의 범주가 사전순으로 되어 있습니다.

범주 redpink를 범주 red로 병합합니다. oldcats에서 먼저 red를 지정하여 병합된 범주로 사용합니다.

oldcats = {'red','pink'};
B = mergecats(A,oldcats)
B = 6x1 categorical
     red 
     blue 
     red 
     red 
     blue 
     red 

mergecatsA(3)의 값 pinkred로 바꿉니다.

B의 범주를 표시합니다.

categories(B)
ans = 2x1 cell
    {'blue'}
    {'red' }

B에는 세 개가 아닌 두 개의 범주가 있습니다.

다양한 항목을 포함하는 categorical형 배열을 만듭니다.

A = categorical({'shirt' 'pants'; 'shoes' 'shirt'; 'dress' 'belt'})
A = 3x2 categorical
     shirt      pants 
     shoes      shirt 
     dress      belt  

A의 범주를 표시합니다.

categories(A)
ans = 5x1 cell
    {'belt' }
    {'dress'}
    {'pants'}
    {'shirt'}
    {'shoes'}

5개의 범주가 사전순으로 되어 있습니다.

범주 beltshoes를 새 범주 other로 병합합니다.

B = mergecats(A,{'belt' 'shoes'},'other')
B = 3x2 categorical
     shirt      pants 
     other      shirt 
     dress      other 

beltshoes의 모든 인스턴스가 값 other로 바뀝니다.

B의 범주를 표시합니다.

categories(B)
ans = 4x1 cell
    {'other'}
    {'dress'}
    {'pants'}
    {'shirt'}

B에는 4개의 범주가 있으며, 그 순서는 더 이상 사전순이 아닙니다. otherbelt 자리에 표시됩니다.

순서형 categorical형 배열을 만듭니다.

A = categorical([1 2 3 2 1],1:3,{'poor','fair','good'},'Ordinal',true)
A = 1x5 categorical
     poor      fair      good      fair      poor 

A의 범주를 표시합니다.

categories(A)
ans = 3x1 cell
    {'poor'}
    {'fair'}
    {'good'}

A가 순서형 배열이므로, 이 배열의 범주에는 수학적 정렬(Mathematical Ordering)인 poor < fair < good이 적용됩니다.

fair 또는 poor 값이 모두 bad가 된다고 가정하겠습니다. A는 순서형이므로 병합할 범주는 연속적이어야 합니다.

B = mergecats(A,{'fair' 'poor'},'bad')
B = 1x5 categorical
     bad      bad      good      bad      bad 

fairpoor의 모든 인스턴스가 값 bad로 바뀝니다.

B의 범주를 표시합니다.

categories(B)
ans = 2x1 cell
    {'bad' }
    {'good'}

B에 두 개의 범주가 있으며, 이 범주는 다음과 같이 수학적 정렬로 나열되었습니다. bad < good.

categorical형 배열을 만듭니다. 이 배열에는 "yes"와 "no"를 의미할 수 있는 여러 범주가 있습니다.

C = categorical(["Y" "Yes" "Yeah" "N" "No" "Nope"])
C = 1x6 categorical
     Y      Yes      Yeah      N      No      Nope 

categories(C)
ans = 6x1 cell
    {'N'   }
    {'No'  }
    {'Nope'}
    {'Y'   }
    {'Yeah'}
    {'Yes' }

pattern을 사용하여 여러 범주 이름을 일치시킬 수 있습니다. 예를 들어 Y로 시작하는 범주 이름을 지정하려면 와일드카드 패턴을 사용하면 됩니다. 와일드카드 패턴을 만들려면 wildcardPattern 함수를 사용합니다.

이름이 Y로 시작하는 모든 범주를 yes라는 하나의 범주로 병합합니다. 그런 다음 이름이 N으로 시작하는 모든 범주를 no라는 하나의 범주로 병합합니다. 결과적으로, 같은 의미를 갖는 값이 모두 동일한 범주에 놓이게 됩니다. 이제 C에는 두 개의 범주만 있습니다.

C = mergecats(C,"Y" + wildcardPattern,"yes");
C = mergecats(C,"N" + wildcardPattern,"no")
C = 1x6 categorical
     yes      yes      yes      no      no      no 

categories(C)
ans = 2x1 cell
    {'no' }
    {'yes'}

입력 인수

모두 축소

입력 배열로, categorical형 배열로 지정됩니다.

병합할 범주로, string형 배열, 문자형 벡터로 구성된 셀형 배열 또는 pattern 스칼라로 지정됩니다. A가 순서형인 경우 병합할 범주는 연속적이어야 합니다.

새 범주로, string형 스칼라 또는 문자형 벡터로 지정됩니다.

확장 기능

버전 내역

R2013b에 개발됨