I have some data with both numerical and string columns. See attached for an example (aa.xlsx).
It has four columns like this:
Header1 Header2 Header3 Header4 1, 4, -9, ABC123 2, NaN, 0, NaN 5, 6, NaN, ABC789
My goal is to convert any NaN values that are in only numerical columns into -999, while leaving the NaN values in string columns intact. The end results should look like something like this:
Header1 Header2 Header3 Header4 1, 4, -9, ABC123 2, -999, 0, NaN 5, 6, -999, ABC789
Here is the code I know will work, if all of my columns are numerical:
%convert any NaN into -999
T1 = readtable ('aa.xlsx', 'PreserveVariableNames',true)Ind_table = isnan(T1{:,:}); T1{:,:}(Ind_table) = -999;
How should I modify it so that it won't do the conversion for columns that are made up of strings?
Many thanks!
Best Answer