Replace missing values in a row with the set of all possible values in that row for a data table.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
jassi singh
am 1 Feb. 2019
Beantwortet: Stephan
am 2 Feb. 2019
If I have a large dataset and there are some missing values in each row. I want to repalace missing values of a row with the set of all possible values of that row. How can I do so?
2 Kommentare
Bob Thompson
am 1 Feb. 2019
I want to repalace missing values of a row with the set of all possible values of that row.
I'm a little confused. Do you want to replace each value with a set of values, replace all missing values with an equal number of possible values, or just attach all possible values at the end?
Akzeptierte Antwort
Stephan
am 2 Feb. 2019
Hi,
the following script should do what you want:
% set options and import data
opts = spreadsheetImportOptions("NumVariables", 5);
opts.Sheet = "Sheet1";
opts.DataRange = "B2:F6";
opts.VariableTypes = ["double", "double", "double", "double", "double"];
Data = readtable("example.xlsx", opts, "UseExcel", false);
Data_new = table2cell(Data);
% manipulate data the way you wish
for k = 1:size(Data,2)
[r, ~] = find(isnan(Data{:,k}));
c = unique(Data{:,k});
c(isnan(c)) = [];
for d = 1:numel(r)
Data_new{r(d),k} = c';
end
end
% clean up
clear opts Data c d r k
The resulting cell array can be seen here:
![cell_array_result.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202479/cell_array_result.png)
Best regards
Stephan
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Tables finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!