How to reorganize the data in table?

조회 수: 2 (최근 30일)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020년 8월 9일
편집: madhan ravi 2020년 8월 10일
I have a large table like this: (the first row is column name "E" and "M")
I want to know how many "blc" has "m" and how many "blc" has "f" and the same thin for "whi". Any idea how?

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 8월 9일
Use groupsummary. Group the data first by E then by M. Groupsummary will tell you the count of each group. Here's an example using the name data for the table.
E=["blc";"whi";"blc";"blc";"whi";"blc";"blc";"blc";"whi";"whi";"whi";"whi"];
M=["m";"f";"f";"f";"f";"m";"f";"f";"m";"m";"m";"f"];
data=table(E,M);
summaryTbl = groupsummary(data,["E","M"])
summaryTbl =
4×3 table
E M GroupCount
_____ ___ __________
"blc" "f" 4
"blc" "m" 2
"whi" "f" 3
"whi" "m" 3
  댓글 수: 4
Cris LaPierre
Cris LaPierre 2020년 8월 10일
Cell vs string. Might have an older version of MATLAB.
madhan ravi
madhan ravi 2020년 8월 10일
편집: madhan ravi 2020년 8월 10일
Ah true, but groupsummary() was introduced in 2018a hence the OP has access to string classes which was there even before 2018 (2016b I believe).

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by