In table, replace NaN with Text (from NaN to "ABCD")
44 views (last 30 days)
Show older comments
Hello, In a column of a table, is there a non-loop way to replace the NaN for any fixed text say "ABCD" ?
In the column that I need the change, it is either NaN or it is text (no numeric)
I tried
T.var3(ismissing(T.var3)) = "ABCD";
But it does not change it to ABCD, it keeps the NaN
also tried
T.var3(isnan(T.var3)) = "ABCD";
1 Comment
Answers (2)
Cris LaPierre
on 15 Oct 2021
NaN suggests you have numeric data in your column (Not A Number). You will have to convert your numeric values to strings if you want to have "ABCD" be a value in your variable.
0 Comments
Image Analyst
on 15 Oct 2021
Like Jan says, you can't do it. Numbers are numbers and characters/string are characters/strings. You could do it with a cell array, but not a table. If the item is a NaN, then that means that column is all numbers. String columns will never be a NaN so that's how I know. And you cannot set an item in a numerical column of a table to a string. You can only replace it with numbers because it's a numerical column. The column would have to be strings, not numbers, if you wanted to stuff "ABCD" into it.
I think you really need to decide what made this table and how they got to be nan's before you can start deciding how to repair the table. Please attach the table in a .mat file.
save('answers.mat', 'T');
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!