Unrecognized table row name
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
LeoAiE
el 6 de Sept. de 2021
Comentada: LeoAiE
el 7 de Sept. de 2021
Hello everyone,
I have a table and I want to subscript using a column contain a string array. Basically, the column is repeated countries names and I used unique to get unique values. Then I wanted to get all the available information from the table about those countries. I understand I will lose some data from other columns, but this is not a concern at this time. I get an error message saying “unrecognized row name”
Any other methods can achieve the results? here is my code and my data
Data = readtable('Test.xlsx');
Data.country = string(Data.country);
Data(unique(Data.country),:)
0 comentarios
Respuesta aceptada
Walter Roberson
el 7 de Sept. de 2021
In order to index by a string or categorical in the first index of a table, the values have to have been set as the RowNames property.
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/730924/Test.xlsx';
Data = readtable(filename);
Data.Properties.RowNames = string(Data.country);
Data(unique(Data.country),:)
You can see from this that every row name must be unique.
The indexing done with the first index of a table is not equivalent to a SELECT operator that would select all matches. Instead, the RowName that is set must be unique, must identify exactly one row in the table.
2 comentarios
Walter Roberson
el 7 de Sept. de 2021
If you want to get at the first match for each country:
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/730924/Test.xlsx';
Data = readtable(filename);
Data.country = string(Data.country);
[~, ia] = unique(Data.country);
Data(ia,:)
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!