Converting Categorical Array/Table to Numerical
Afficher commentaires plus anciens
Hello!
I have a 23000x4 set of data that is a table (called temp). It is all numbers except for the times data was missing it was filled in with 'NA', therefore the table is categorial. I am looking to change it to a numerical and have all the 'NA' changed to 'NaN' so I can run max and min and those kinds of things on it without running into issues. Thank you for the help!
12 commentaires
Steven Lord
le 10 Juin 2020
Can you show us a representative example of your data? Say show us 3-4 rows of your data, at least one with NA and at least one with non-missing times data.
I suspect standardizeMissing can help you, but depending on how the data is stored converting your times data to datetime or duration may be of more use.
Claire Hollow
le 10 Juin 2020
Steven Lord
le 10 Juin 2020
Can you show us the output of whos on the variable that contains this data, and perhaps show those four lines from your variable as MATLAB displays them? This would help us ensure our suggestions take the class of the variable in which this data is stored and the classes of the data stored in that variable itself into account.
I'm thinking something like:
% Create sample data
load patients
patients = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
% Here's the information I'm interested in
whos patients
patients(1:4, :)
Claire Hollow
le 10 Juin 2020
Adam Danz
le 10 Juin 2020
FYI; "NA" or "NaN" is a missing value.
Adam Danz
le 10 Juin 2020
Of course the categorical values that are numeric can be converted to numeric values but that approach is just a bandaid. The better approach would be avoid using categorical classes on numeric values in the first place.
How did these values end up to be categorical?
Claire Hollow
le 10 Juin 2020
Adam Danz
le 10 Juin 2020
That's a completely different question.
If you look at the documentation for max() you'll see that one of the inputs specifies whether to compute max() across columns, rows, or any other dimension.
Claire Hollow
le 10 Juin 2020
Adam Danz
le 10 Juin 2020
As I mentioned above, the best solution is to not convert the values to categorical in the first place. How did they end up to be categorical?
Claire Hollow
le 10 Juin 2020
Adam Danz
le 10 Juin 2020
What function did you use to import it? You can control the class of the data you're importing. A csv file doesn't control that for numeric values.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur String Parsing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!