Replace NaN's in a table - I need some help
Afficher commentaires plus anciens
Hello all, I have a table namely T2,
it has 12 columns. in all of these columns I have some NaN values. I would like to replace NaNs in the 1 to 7 column. the problem is I want to replace these NaNs by non-NaN values in each column (the value in each row is stable).
for example ( for two columns):
NaN NaN NaN
NaN RAD NaN
Behezad RAD MORD
NaN NaN MORD
I want:
Behezad RAD MORD
Behezad RAD MORD
Behezad RAD MORD
Behezad RAD MORD
for each column. it is important that every column has it's own value. I don't want to have any change in column 8 to 12 NaNs
thank you, I wait for your kindly answers.
best regards
7 commentaires
Image Analyst
le 19 Déc 2019
What do you want to replace the nan's with? The nearest non-nan value? A linearly interpolated value between the two nearest non-nan values?
Also, it looks like your columns are strings. If they're strings, then you can't have nan's in a column of strings. Nan's can only appear in a column of numbers I believe. You could have null strings '' though.
Image Analyst
le 20 Déc 2019
Please attach the table in a .mat file to make it easy for people to help you. Don't make us have to create sample data just to help you when you already have it. If it's too hard to help, many people just won't.
BN
le 20 Déc 2019
Image Analyst
le 20 Déc 2019
But what if there is a missing one and two different numbers above and below. Which do you choose?
And if a string is missing, how valid is it to just take one of the nearest values? Like if I was in the table, and my middle name and age were missing, how valid is it to make my middle name and age the same as from whomever happens to be above or below me in the table?
BN
le 20 Déc 2019
BN
le 20 Déc 2019
Réponses (2)
Ridwan Alam
le 19 Déc 2019
Modifié(e) : Ridwan Alam
le 19 Déc 2019
T2.col1(ismissing(T2.col1)) = "Behezad";
T2.col2(ismissing(T2.col2)) = "RAD";
T2.col3(ismissing(T2.col3)) = "MORD";
2 commentaires
Ridwan Alam
le 19 Déc 2019
Sure, Behzad. Please share what you've tried to automate this. And if there is any specific error or question, I would be glad to help. But, I am not willing to write your whole code for you.
BN
le 20 Déc 2019
0 votes
Catégories
En savoir plus sur Data Type Conversion 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!
