How do I specify a variable from a table that uses words and not numerical values
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Elias Marcelino
el 14 de Abr. de 2021
Editada: Campion Loong
el 15 de Abr. de 2021
I'm trying to use an if statement to equate to 'Na'. I'm not sure how I would write the variables out. Such as 'orange peel', 'NA', 'wrapper', etc.
0 comentarios
Respuesta aceptada
Campion Loong
el 14 de Abr. de 2021
Editada: Campion Loong
el 15 de Abr. de 2021
I would use a categorical for trashTags.
trash = readtable('Litterati_processed_data.csv');
trash.Tags = categorical(trash.Tags);
Alternatively, it's more memory efficient to directly read the Tags in as categorical (i.e. rather than converting after import). Use ImportOptions and the corresponding detectImportOptions:
% I am guessing your file layout here. Tinker to suit your needs
opts = detectImportOptions('Litterati_processed_data.csv', 'Delimiter', ',');
opts = setvartype(opts,'Tags','categorical'); % directly read "Var1" in as categorical
If your 'NA' actually means 'not applicable', you can read that in as missing value too:
opts = setvaropts(opts, 'Tags', 'TreatAsMissing', 'NA');
Now just read it in with your configured options:
trash = readtable('Litterati_processed_data.csv', opts);
% Just count the number of "NA"
n = nnz(t.Tags == 'NA')
% Or if you had treated "NA" as missing at import
n = nnz(ismissing(t.Tags))
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Tables 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!