How to reorganize the data in table?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Zeynab Mousavikhamene
el 9 de Ag. de 2020
Editada: madhan ravi
el 10 de Ag. de 2020
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?
0 comentarios
Respuesta aceptada
Cris LaPierre
el 9 de Ag. de 2020
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 comentarios
madhan ravi
el 10 de Ag. de 2020
Editada: madhan ravi
el 10 de Ag. de 2020
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Numeric Types en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!