Cell column to double from table

1 visualizzazione (ultimi 30 giorni)
Amina Ag
Amina Ag il 23 Mag 2021
Commentato: Amina Ag il 27 Mag 2021
Hello,
I have a txt file that i have uploaded using readtable. This gives me a table of 4000000x34 variables. Some of these variabled are doubles, while some are cells. I have tried to transform the cell coulmns to doubles using cell2mat and str2double, but only get NaNs or error messages.
Some of my variables look like this: The cell ones containt the '''.
How can I transform the cell columns to doubles? Will need this when running my regression.
  6 Commenti
dpb
dpb il 25 Mag 2021
Modificato: dpb il 26 Mag 2021
There is no item_33 in the uploaded dataset so I dunno about that.
When your data aren't properly formatted, somtimes detectimportoptions needs some extra help:
opt=detectimportoptions('b.xlsx');
opt=setvaropts(opt,'item_2','Type','categorical','FillValue','YourFillValue','Prefixes',"'",'Suffixes',"'");
opt=setvaropts(opt,'item_50108','Type','double','TrimNonNumeric',true);
tB=readtable('b.xlsx',opt);
yields
>> tB(1:8,{'item_2','item_50108'})
ans =
8×2 table
item_2 item_50108
_____________ __________
M 63.40
M 51.62
M 0.00
M 45.31
YourFillValue 51.54
M 22.22
M 70.20
M 22.12
>>
You can deal with all of the issues either by defining the import objects fields to match known data types and formats or by cleaning up the data fields afterwards.
The problem with your categorical substitution is you undoubtedly didn't have a categorical variable on the RHS and you'll have to use the form shown in the documentation for categorical to add categories for values that aren't in the dataset that is converted if don't use the fill missing on import route as shown above.
Amina Ag
Amina Ag il 27 Mag 2021
This worked perfectly!
Thank you so much for your help. It has been a real struggle and feels amazing now that it is solved. Highly appreciate your time and answer.
All the best!

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by